Expected expression, got keyword 'else'


#1



Build "Rock, Paper, Scissors"


SyntaxError: expected expression, got keyword 'else'

I dont undestand what I have done wrong

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

you should close your else if choice1 is rock before starting your else if choice1 is paper


#3

Your if (choice2 ===) statements are nested inside else if (choice1 ===) statements. So you have to make sure you use correct syntax and close them off before moving on to your next else if (choice1 ===) statements.

for example:
if (choice1=== choice2) {
code for tie
} <----- end of code for tie condition
else if (choice1 === x){
nested if (choice2 === y){
code x wins
} <----- end of code if x wins
else {
code y wins
} <----- end of code if y wins
} <------end of code for else if


#4

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