mardi 31 mars 2015

Unexpected token else, not a semicolon after if statement

Trying to write a rock paper scissors game, using codecademy to learn. I've seen a lot of people talking about this error and it being related to using a semicolon after an if statement but I don't know if I'm completely missing something or it's something different. Here's the code, it's a little weird to understand (and least to me), but hopefully you'll see what I didn't



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

Aucun commentaire:

Enregistrer un commentaire