7. choice1 is paper? / syntax error: unexpected token else


#1

Can someone please let me know whats wrong with my code. Been stuck on this one for days! 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 "scissors wins";
    }

};


#2

Here is your code with the proper formatting:

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

Do you see? First else is in the wrong place. It should belong to if (choice2 === "scissors"), not to if (choice1 === choice2).