javascript - Unexpected token else, not a semicolon after if statement -
trying write rock paper scissors game, using codecademy learn. i've seen lot of people talking error , being related using semicolon after if statement don't know if i'm missing or it's different. here's code, it's little weird understand (and least me), you'll see didn't
var compare = function(choice1, choice2) { if(choice1 === choice2) { return "the result 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"; } } }; }
try removing }
@ end of code (line 21) , place on line 12 instead.
fixed code:
var compare = function(choice1, choice2) { if(choice1 === choice2) { return "the result 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"; } } };
Comments
Post a Comment