syntaxError: unexpected token 'else' 5/5


#1



https://www.codecademy.com/courses/javascript-beginner-en-x9DnD/0/5?curriculum_id=506324b3a7dffd00020bf661


The error message I'm getting is syntaxError: unexpected token 'else'. The problem is at the point of deciding whether or not to race Bieber. I'm not seeing something wrong here and I've been staring for a while. Thanks for the help, folks!


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.'")
}


#2

The code snippet you've posted does not generate this error. Kindly post your full code. Thanks!


#3

@systemninja73472, a possible reason for that error is because you haven't ended your console.log statement in your if statement with a semicolon. Try that, and reply if it doesn't work.


#4

JavaScript has automatic semi-colon insertion. Missing semi-colons only cause a problem in strict mode, which isn't the case here.


#5

Thanks for informing me @gaurangtandon. In which case I agree. This isn't the code providing you with the error. Please paste your full code @systemninja73472


#6

@bartholomewallen

Here's the full code.

// Check if the user is ready to play!
confirm("I am ready to play!");
var age= prompt("What's your age");
if (age<13){
    console.log("You're allowed to play, but I take no responsibility!")
};
else{
    console.log("Good! Get ready.")
};
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.'") 
}

#7

The semicolons after your closing curly braces in your first if/else code are stopping your code in its tracks.


#8

Ah! Fixed it. Now it works. Thanks!


#9

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