7. What if choice1 is paper? - Unexpected token else


#1

Hi guys,
Running into an unexpected token else error and I can't figure out why..
I've gone through the other posts where most people are running into the mistake of too many (or not enough) parentheses but I can't find that issue with mine..
Can someone provide some assistance please?

My Code:

var compare = function(choice1, choice2) {
// Both choices are the same
if(choice1 === choice2) {
return "The result is a tie!";
}
// What if choice1 is rock?
else if (choice1 === "rock") {
if(choice2==="scissors")
return "rock wins";
}
else {
return "paper wins";
}

// What if choice1 is paper?
else if (choice1==="paper") {
if (choice2==="rock")
return "paper wins";

}
else {
return "scissors wins";
}
}


#2

Remember, you need a '{' after an if statement:


#3

Oh great, thanks!
Had them in the wrong place..


var compare = function(choice1, choice2) {
// Both choices are the same
if(choice1 === choice2) {
return "The result is a tie!";
}
// What if choice1 is rock?
else if (choice1 === "rock")
if(choice2==="scissors") {
return "rock wins";
}
else {
return "paper wins";
}

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


#4

I don't know if you still get a problem, but you also have to put '{' after your else if statements :smiley: :