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


#1


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


#2

//This else is out of place :slightly_smiling:


#3

Also here you forgot parenthesis and semicolon


#4

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.


#5

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:

@secretshadowleague


#6

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


#7

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


#8

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

#9

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:


#10

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


#11

Thanks for that, needed that :slight_smile:


#12