My else won't work, keeps saying it 'expected an identifier'


#1

When I type in my else the little red X comes up and says "expected an identifier and instead saw 'else' " and it won't let me continue and on the console thing it says"SyntaxError: Unexpected token else . So far I have been writing the lines of code and then skipping to the next lesson but now I'm at the end of the course so I can't go on. Can someone help?
https://www.codecademy.com/en/courses/javascript-beginner-en-x9DnD/0/7?curriculum_id=506324b3a7dffd00020bf661

confirm("I'm ready to play!");
var age = prompt("What's your age?");
if (age < 13);
{
    console.log("Your allowed to play but I'm not responsible");

} else; {

    console.log("Have fun!");
}
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("Please rate 1 to 10");
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

You have put semi colons after if and else keyword...

remember how if/else statement looks like?

if (condition) {
    something here
} else {
    something here
}

#3

now it says the same thing but also it says "missing semicolon before statement"


#4

You have put semi colon after if and else keyword...
There is semicolons after if too... that's why its throwing an error.!
(check your code and you will find it) :slight_smile:


#5

ok thank you i will try that


#6

Do reply if it worked or not!
:thumbsup:


#7

now on the if it says expected '(' and instead saw ';'


#8

Can you post your code?


#9

yeah sure ...............................


#10

confirm("I'm ready to play!");
var age = prompt("What's your age?");
if; (age < 13);
{
console.log("Your allowed to play but I'm not responsible");

} else; {

console.log("Have fun!");

}
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("Please rate 1 to 10");
if; (feedback > 8);
{
console.log("Thank you! We should race at the next concert!");

} else; {

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

}


#11

You have not deleted semicolons after and before of if
;if (some condition) ; is wrong...
also delete all semicolons after else ;

Look at this if/else statement, It always structured as given below..

if (condition) {
    something here
} else {
    something here
}

can you see any semicolon before if and after (condition) or after else?


#12

for some reason now only the first else has an X

confirm("I'm ready to play!")
var age = prompt("What's your age?")
if (age < 13)
{
console.log("Your allowed to play but I'm not responsible")

} else {

console.log("Have fun!")

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("Please rate 1 to 10")
if (feedback > 8)
{
console.log("Thank you! We should race at the next concert!")

} else {

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

}


#13

Because statements inside if/else always ends with semicolon and you eliminated all of them. Tho you have only asked to delete semicolons that is JUST before if and JUST after if () and JUST after else,
( I highlighted which semicolons have to be deleted :slight_smile: )
do that and reply what are you getting now?


#14

Thanks now it works!!!!


#15

Youre welcome!! :slight_smile:
Keep up the good work!! :thumbsup:


#16

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