user3425956
user3425956

Reputation: 25

Codecademy "SyntaxError: Unexpected token else"

I'm doing the codecademy js course, and I'm at the part with rock paper scissors. When I save the code it says "SyntaxError: Unexpected token else". What did I do wrong? This is my code:

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");
        }
    }
    else if (choice1 === "paper");
    {
        if (choice2 === "rock")
        {
            return("paper wins");
        }
        else
        {
            return("scissors wins");
        }
    }
    else if (choice1 === "scissors")
    {
        if (choice2 === "paper");
        {
            return ("scissors wins");
        }
        else
        {
            return("rock wins");
        }
    }
}

Upvotes: 2

Views: 115

Answers (2)

Piper McCorkle
Piper McCorkle

Reputation: 1084

If you'll see on the following line:

else if (choice1 === "paper");

, there's a semicolon where there shouldn't be.

Upvotes: 0

Nikhil Aggarwal
Nikhil Aggarwal

Reputation: 28475

Remove semicolon after if/else if/else

For e.g.

   else if (choice1 === "paper");

Upvotes: 1

Related Questions