What if choice1 is rock


#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";
}
}

I'm having a problem with the else if situation it keeps prompting " saw else instead of an indentifier"

what should I do to solve this.


#2

if (choice1 === choice2);
return "The result is a tie!";
}; // unnecessary semi-colon

see comment in code


#3

if i remove or add the semi-colon the result is the the same

next to the else if statement it says "expected an indentifier and instead saw 'else' "
"missing ; before statement"


#4

if (choice1 === choice2);

this line, another unnecessary semi-colon and a missing opening curly brackets ({)


#5

here is my current code, i have also fixed the minor mistakes you had pointed out

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";
}
}

but the problem is still the same


#6

so this is currently your function:

var compare = function (choice1,choice2){
if (choice1 === choice2){
return "The result is a tie!";
}
// else if should be here
};

see comment, the else if should be part of the function


#7

ok, thank you that solved my problem


#8

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