SyntaxError: Unexpected token else


#1

Please help, I am receiving the error message "SyntaxError: Unexpected token else".
I have been through the code a dozen times, counted my curly brackets etc, but I must be missing something..


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

Okay, solved it in the end. I deleted all of the semi-colons apart from the one at the very end. Still, don't quite understand why that would have made the difference. Any explanations would be appreciated.


#3

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