6/9 Unexpected token else?


#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";
}

}


#2

it says there is an unexpected token else. I cant find it for the life of me. Please help. Cheers me ducks


#3
  1. at if condition line ; semi-colon shouldn't be

2- one missing } at the last line


#4

thanks bud, (over 20 characters)


#5

In case you interested here is a post about what the semicolon after the condition does to your code:


#6

Another common problem that doesn't apply to your code but did for mine seems to be that I closed my compare function before I wrote the else if statement, so that's the reason for the "unexpected else token." Your code should look something like this:

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")
}
}
}