What if choice 1 is Paper? - Unexpected Else token?


SyntaxError: Unexpected token else

It should be correct, I so far can't see why not..

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"   
            return "scissors wins";


//This else is out of place :slightly_smiling:


Also here you forgot parenthesis and semicolon


The else statement you mentioned worked with the previous exercise. I don't see how it will cause a problem now. I am completely lost.


I´m not quite sure but its´ because you have an else if after your else just a few lines after. so it is like this : if > else if>else>else if I don´t think that is correct :sweat:



So should it be if>else if > else if> else if> else? or something with that format?


If I´m not mistaken then, yes it should fallow that line of format!


H your code should have that strutture

else if (condition) { # open the else if statement
    if (condition) { # open the if statement

    } // close the if statement
    else { // open the else statement

    } //close the else statement
} // close the else if stament

} // after all your else if statement you should close the compare function


Thank you all. I have finally managed to figure it out, with everyones' help of course. I had my else statement outside of the else if statement, meaning I couldn't do anymore if statements. I feel so stupid now :joy:


3 posts were split to a new topic: Anyone know what is wrong with my code? Please tell me!


Thanks for that, needed that :slight_smile: