Excersize 5. Can you find what is wrong here?


#1
// Check if the user is ready to play!
confirm("I am ready to play!")
var age = prompt("What's your age");
if (age < 13)
{
    confirm("Are you sure you want to play?");
} else {
    console.log("Good luck!");
}
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.'");

Can you help, I'm stuck and my error is There was a problem with your syntax.


#2

confirm("I am ready to play!")
var userAnswer = prompt("Do you want to race Bieber on stage?")

While javascript does not require that you add a semi-colon " ; " it can cause problems. Try adding semi-colons to the end of those two lines of code and see if that fixes your code.

If not, that's because the real error is that you don't have closing bracket " } " at the end of your last else statement.


#3

Hi, I'm having a similar problem please see below.
// 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 can play but I can take no responsibility");
}

else (age >13);
{
console.log("Yey you can play on");
}

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(userAnswer ==="No"); {
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");

}


#4

Remove all the semicolons after each if and else statement:

if ();

Should be

if ()

#5

TBH I only put those in out of desperation, have taken them out but am now getting the SyntaxError: Expected ';'

// 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 can play but I can take no responsibility");
}

else (age >13)
{
console.log("Yey you can play on");
}

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(userAnswer ==="No") {
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");

}