Help: "SyntaxError: expected expression, got keyword 'else' "


#1

This is my code. I don't know why I am getting the Syntax error
// Check if the user is ready to play!
confirm("Get ready!");
var age = prompt("What's your age?");
if(age<13)
{console.log("You will be ready in a few years")}
else
{console.log("Let's begin")}
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.'")};


#2

Hi this part remove the ; after the if condtion

if(age<13); <== this one

#3

Didn't work. I'm still getting the same error.


#4

can you post your code?


#5

remove ; after {
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!")
}
ok?? :slight_smile:
@namitsingh


#6

@rcodeman nope that didn't work


#7

@wizmarco here it is, I made some changes
confirm("Get ready!");
var age = prompt("What's your age?");
if(age<13)
{console.log("You will be ready in a few years")};
else
{console.log("Let's begin")};
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.'")};


#8

here remove the ; after the closing }

if (age < 13) {
    console.log("You will be ready in a few years")
}; <== this one

here too

if (userAnswer === "yes") {
    console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!")
}; <== this one

#9

see

confirm("Get ready!");
var age = prompt("What's your age?");
if(age<13)
{
console.log("You will be ready in a few years")
}
else
{
console.log("Let's begin")
};
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.'")
};
@namitsingh


#10

That worked!
THANK YOU @wizmarco and @rcodeman!!