Javascript Rock, Paper, or Scissors

Does anybody know why it is not printing ‘error!’ to the log? I’m failing to see any reason why it’s not.

if (userInput === "rock" || "paper" || "scissors")
// is equivalent to:
if ( (userInput === "rock") || ("paper") || ("scissors") )

Regardless of whatever value is assigned to userInput, the second operand "paper" is truthy, so the overall condition will always evaluate to True.

Your condition is not the same as:

if ((userInput === "rock") || (userInput === "paper") || (userInput === "scissors"))
2 Likes

ah, makes sense now. Thank you.

1 Like