What if choice1 is paper?


#1

if (choice1 === choice2) {
return "The result is a tie";
}
else if (choice1 === "rock") {
if (choice2 === "scissors") {
return "rock wins";
}
else {
return "paper wins";
}
}
};

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

whats wrong with this?


#2

Check your syntax after your else statements. Semicolons are used to let your code know when to stop. You have one right before your else if leading to your code for the "paper" option and repeat the error for your "scissors" code. Also, keep track of which curly braces correspond to your if statements and which pair to your nested ifs. It's tricky at first.


#3

Sorry but this question is driving me crazy too:

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

}
else if(choice1 === "paper") {

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

}
}

I've checked the curly brackets, tried different variation, what am I not seeing?


#4

OK, so I copied the above code, RESET the page then pasted it back in and it worked! Why couldn't it just work the first time?


#5

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