What is wrong with this syntax?


#1

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

Your problem is you're not closing your statements like you need to. It should look like this:
var compare = function(choice1, choice2)
if (choice 1 === choice2) {
return "the result is a tie";
} else if (choice1 === "rock") {
if (choice2 === "scissors") {
return "rock wins";
}
}; else {
return "paper wins";
};
};
};
You're leaving some statements hanging. You see, if you open an if statement, and put another if statement within the first, then you have to close them both. Also, you need more semicolons. If it still doesn't work, try refreshing your browser or experimenting taking away and adding spaces and semicolons. If you're still confused, look at your if/else statements that are now in the comment.


#3

Hi,

you are missing the opening and closing curly brackets around the function. It should be like this

var compare = function(choice1, choice2) {
  ...
}

Thanks

Keith


#4

As @keefyboooo already said + do not use semicolons after conditions. Here is an explanation why:

https://www.codecademy.com/forum_questions/52373a75548c3515940000dc#answer-529fa36052f863bb58000338


#5

Thx. Adding brackets worked :smile: