What is wrong with this ? (What if choice1 is paper ?)


#1

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


#2

@willynok I think one of your closing curly braces should be before the else, so that you only have one } after the return command.


#3
  • semicolon after "scissor wins" ?
    try this ?
    else if (choice1 === "paper") {
    if (choice2 === "rock") {
    return "paper wins";
    } else {
    return "scissors wins";
    }
    }

#4

Pointing out the semicolon is ok, although it shouldn't create an error here. Could you point out what the difference is between your code and the one from @willynok?

@freginold No acutally it's like @willynok did. What you intend to do is to check what could happen when choice1 is paper. Well it could be a tie, which is already checked and otherwise it the opponent could have chosen rock in which case paper wins. And else meaning not choice2 === rock it should return scissors wins because that is what is left. If you'd swap the curly bracket to before the else, now else would be the alternativ to choice1 === "paper" which has a whole different meaning.

Hope this is not too confusing.


#5

yeah you're right it seems my code is not different from willynok's one, i think i was just putting it a better presentation just in case, but nothing more


#6

@haxor789 ah good point, thanks for clarifying!