Cannot recognize else token


#1

Hi there, no matter what I do i cannot get this code to work. apparently the else token is not recognized. I have tried this with and without semi-colons. any help would be amazing!

confirm("I am ready to play!");
var age = prompt("What's your age");
if(age < 13)
{
console.log("You can't play noob!");
}
else(age >= 13);
{
console.log("You are ready to play!");
}
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("give my game a rating out of 10");
if(feedback < 8)
{
console.log("Thank you! We should race at the next concert!");
}
else(feedback > 8)
{
console.log("I'll keep practicing coding and racing.");
}


#2
else (feedback > 8)

else statements don't contain arguments. If you want to you can change that to either of the following:

else {

or

else if (feedback > 8)

If that works let me know, otherwise I haven't looked hard to see if there are any other errors in your code.

Message me if you need anything!

Your friendly neighborhood coder,
-LoLMaN


#3

HI there, I tried to private message you but I don't think you can in code academy :smile:

thanks so much for your reply,but I can't get the code to work even with the changes you suggested. any help would be great! I think it might be an error on the code academy side? but im not sure.


#4

When I run your code through http://esprima.org/demo/validate.html I get this section as the spot where "else" is an issue.

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

Take a closer look at your if statement:

if(userAnswer = "yes");

; is like a period. You've closed the thought out here, so that it doesn't know what to do with the rest of your if/else.

Also, while we're looking at this section, you've also made the same mistake I keep making: the comparative is === not =

Hope this helps!


#5

In addition to what @tagplayer25484 said, the same mistake was repeated above in the code:

else (age >= 13);

Two major mistakes are:

else (age >= 13);
    ^           ^
    1           2

1: else statements don't have parameters, if you want to keep the parameter the parenthesis you'll have to make that an "else if" statement.

2: As soon as you put a ";" / "semi-colon" at the end of a line of code it's saying "Hey stop here, you are done." On an IF statement that's like saying there is nothing in the execution of my if statement. So the computer is just going to look at you and shake it's head in sadness.

else if(age >= 13) {...}

or

else {...}

either of these will work! :smiley:


#6

Awesome, I got it working! thank you so much guys :smiley: