6/9 Unexpected token else


#1

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

Any help is appreciated, I've been trying different things with no success for about a half hour or so now. Thanks


#3

You are using a semi-colon-; in IF ELSE-IF statement structure.
if (choice1 === choice2);{
For the Javascript Interpreter a semi-colon-;
is an End-of-Statement indicator,
leading to the REST of statement is NOT evaluated.

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate
-1 of the build of the IF ELSE-IF statement structure
-2 the truth-Table


#4

As @leonhard_wettengmx_n already says the semicolons after conditions are a problem, I wrote a longer post ofter here:


@lolman What is the problem about this line?
@danimal1 Seems like your also missing a } after the very end to close your function.


#5

@haxor798

Nothing is wrong with this line, I made a mistake and I do apologize for the confusion.


#6

No problem. Then maybe delete them so no bypasser gets confused :smile:


#7

I read you post and found it helpful. I was able to get rid of "unexpected token else", but now I'm getting "Oops, try again. Your code returned 'paper wins' instead of 'rock wins' when the inputs are rock and scissors". Thanks again for the help.


#8

Oh yes here it needs to be "scissors" not "scissor" so as the case is not matching (even so it's just a little bit) it chooses the default case.


#9

Thank you so much! This helped a lot!