6/9 syntax error unexpected token else, NEED HELP


#1

this is my code, it doesnt work for some reason i even copied and pasted the code from the hint
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";
}

}
}


#2

With

var compare = function(choice1, choice2) {
    if(choice1 === choice2)  {
        return "The result is a tie";
    }
}

you have closed the compare =function=

Please read
= http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on

  • the build of the IF ELSE-IF ELSE-IF statement structure

#3

try removing one of the " } " you have


#4

Im stuck on differentiating between my code and the suggested code. It is giving me an error.
My perception is that the code is identical minus minor spacing.
Suggested code:
if(choice1 === choice2) {
return "The result is a tie";
}

else if(choice1 === "rock") {

if(choice2 === "scissors") {
    return "rock wins";
}
else {
    return "paper wins";
}

}

My code:
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";
}
}

Result:
"SyntaxError: Unexpected end of input"

Any input is much appreciated!


#5

@mikeev85,
The SyntaxError: Unexpected end of input
is the indication that you are forgetting a closing-curly-bracket-}
with which you close the FUNCTION-BODY....


#6

I understand. But when I compare the suggested code and my code the amount and order of all brackets is identical. I still dont get what I did wrong.


#7

@mikeev85,

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";
        }
    }
};  //<====Closing the FUNCTION-BODY

#8

Thank you very much. Need to refresh my memory, i stopped learning 2,5 months ago, just started again, thanks again


#9

@teroy655,

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b


#10

Ive read it and already finished rock, paper, scissors my problem was the fact that i forgot to close the variable at the end of each code and then reopen it, but ive started introduction for loop already C:


#11

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
var compare = function (choice1,choice2) {
if(choice1 === choice2) {
return "The result is a tie";
}

else if(choice1 === "rock") // < --do not put { after the code

if(choice2 === "scissors") {
    return "rock wins";
}
else {
    return "paper wins";
}

}