Hi everyone. Please help me


#1

This is my code:

var compare = function(choice1, choice2){
if(choice1 ===choice2){
return "The result is a tie!" ; }
else if(choice1==="rock") {
if(choice2 ==="scrissors"){ return "rocks wins";}
}
else{
return"paper wins";}
}
else if(choice1 === "paper") {
if(choice2 === "rock") {
return"paper wins";
} else {
return"scissors wins";
}
}

===========

I got the error: SyntaxError: Unexpected token else..
I don't understand what I'm doing wrong


#2

This error message usually indicates a problem with too few, too many or misplaced curly braces. Move all the closing braces to the own line and check they are matched pairs around everything that is supposed to have a block.

... = function () {

};

Code that is scrunched up like this is hard to debug...

if(choice1 ===choice2){
return "The result is a tie!" ; }
else if(choice1==="rock") {
if(choice2 ==="scrissors"){ return "rocks wins";}
}
else{
return"paper wins";}
}

A careful eye can spot the error right off, but for one who is still learning, the obvious is rarely ever so.

Can you spot the error?


#3

Yep, finally I got the error. Thank you! :slight_smile:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.