Problem with if/else


I have recently begun taking JavaScript again and have noticed an odd phenomena. The website seemingly does not recognize the word else in my program. Specifically at the bottom here.

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

Here is the error message:

Oops, try again. There was a problem with your syntax.

When I look in the console all I get is this:

SyntaxError: Unexpected keyword 'else'

What is the problem? I have tried refreshing, restarting the browser, even restarting my computer. Ayuadame, por favor.


@imacrazypancake the problem is with the semi-colon after your if statement:

if (userAnswer === "yes"); {

the semi-colon tells the interpreter that it's the end of the command, so it doesn't expect to see an else. Remove that semi-colon and you should be fine.


Thank god for you! :smile:


Well crap. I happened again, the else keyword is not expected or whatever.

var compare = function (choice1, choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!"
    else if (choice1 === "rock") {

        if (choice2 === "scissors") {
            return "rock wins";
        else {
            return "paper wins";


What is the problem? I check for semicolons!

Please help.


delete ";" before "else if"