I can't figure out where the syntax error is


#1

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

    else if (choice1 === "paper") {
    } if (choice2 === "rock") {
        return "paper wins";
    } else {
        return "scissors wins";
    }

there is a problem with your {}. after else if you have a closing } to much and after else you therefore lack a closing }:

    else if (choice1 === "paper") {
        if (choice2 === "rock") {
            return "paper wins";
        } else {
           return "scissors wins";
        }
    }

#3
else if (choice1 === "paper") {
      if (choice2 === "rock") {
        return "paper wins";
    } else {
        return "scissors wins";
    }
}

This is how I switched it and it still gives the same error. Shouldn't it be exactly like choice1 === "rock"?


#4

yes and that case should look like the one you just wrote :smile: (both need to be fixed)


#5

Haha that worked! Weird it passed choice1 as rock when it was incorrect then, Thanks!


#6

The problem is that you {} matched, they just not matched where they should have. So it was no error in the rock case but by adding another case you have an else if following on an else which is impossible so there you got the error.