Rock, Paper, Scissors Logic Error

I don’t understand why my logic is failing. I’m returning the userInput by default and catching the errors. But when change the code to see if the userInput equals rock, paper, or scissors and return “wrong Input” by default it works fine. I feel like I shouldn’t be running into this issue. Can someone provide some clarity.

https://www.codecademy.com/courses/introduction-to-javascript/projects/rock-paper-scissors-javascript

const getUserChoice = userInput => {
  userInput = userInput.toLowerCase();

  if (userInput  != 'rock' || userInput != 'paper' || userInput != 'scissors') {
    return 'Wrong Input';
  } 

  return userInput;
}

console.log(getUserChoice('Paper'));

The problem is that you’re checking the input with the ‘OR’ operator rather than the ‘AND’ operator.
In your example code you return ‘Wrong Input’ if one of the conditions evaluates to truthy. If you pass ‘Paper’ as an argument, the conditions userInput != 'rock' and userInput != 'scissors' are true, so ‘Wrong Input’ is returned since only one of the conditions needs to be true for the code block to be executed.

2 Likes