It keeps saying Syntax Error


#1


SyntaxError: Unexpected token else

var yourAge = true;
var yourAge = prompt("What's your age?");
if(yourAge < 13)
{
    console.log("You are allowed to play, but I take no responsibility if you die.");
}
else 
{
    console.log("Alright! Let's go!!!")
}
    console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
    console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");
var userAnswer=prompt("Do you want to race Bieber on stage?");
 if(userAnswer="yes")
 {
    console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
  }
else
 {
     console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
 }
 var feedback = prompt("Rate this game from 1 to 10, please.");
 if(feedback < 8)
 {
     console.log("Thank you! We should race at the next concert!");
    else
{
    console.log("I'll keep practicing coding and racing.");
}


#2

Hi @magicmetal03

You're defining yourAge as a boolean on line one, then defining it as another variable type, an integer, on line two. The simplest way to fix this is by removing var yourAge = true; on the top line. Hope this helps.


#3

I did what you told me, but it didn't work.


#4

Are you still getting the same syntax error?


#5

Yes, I'm still getting the same error.


#6

Does the error have anything other than "Syntax error"?


#7

Hey you mixed up brackets at the end of your code. Check them again.I have run your code for you and it is good apart from that bottom part
Have a look below:

console.log("Thank you! We should race at the next concert!");}

else{

console.log("I'll keep practicing coding and racing.");

};

Pay attention to bracket as they are easy to omit . Well done on coding so much!

if(userAnswer="yes") this should be changed as well


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.