SyntaxError: Unexpected token if
24,401
Should be:
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";
}
Or neater:
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"
}
}
Author by
Admin
Updated on June 19, 2020Comments
-
Admin almost 4 years
I'm currently learning javascript and I keep having this error!!!
This is my script:
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"; }