Syntax Error - Unexpected token else


#1


I am getting an error that says: "SyntaxError: Unexpected token else"

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!";
        }
    }
}


#2

Remove one of the braces.


#3

Hm... I removed it and it still is returning the error


#4

Now re-insert the brace before the else if.


#5

OH I totally get it!!! Thank you!!!


#6

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