Reputation: 75
I'm doing Codecademy to get a better understanding of JavaScript and it's saying the code I'm writing is wrong. But I don't know where it's going wrong. The debug message coming up is:
"Missing an identifier and instead saw 'else', missing ';' before statement"
This issue comes up a lot as I'm writing can anyone let me know what exactly that debug message means so I don't have to come crawling back to you experts? Haha. Anyways, here's the 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");
}
}
compare();
Upvotes: 0
Views: 70
Reputation: 16438
It 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");
}
}
}
compare();
I can only guess what this function is supposed to look like
Upvotes: 2
Reputation: 32681
Easy to see if you properly indent your code:
var compare = function(choice1, choice2) {
if (choice1 === choice2);
return("The result is a tie!");
}; // this ends the function, not the if!
else if(choice1 === "rock") {
if(choice2 === "scissors") {
return("rock wins");
}
else {
return("paper wins");
}
}
Upvotes: -1