Trouble with Rock, Paper, Scissors Pt. 7


#1


I keep getting "SyntaxError: Unexpected token else.

I've looked around on the forums and I still can't figure out what's wrong. Please help. Thanks.


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("sciscors win");
        }  
}


#2

your code should be like

else if(condtion) {

    if(condition) {
        return something;
    } //close if
    else {
        return something else;
    } //close else
} //close else if

if else should be inside of elseif.In your code else is outside of elseif.

after closing elseif close the function

and return doesnt need bracket


#3

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