Https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-i/modules/fecp-learn-javascript-syntax-functions/projects/rock-paper-scissors-javascript

hi everybody! I am working the Rock, Paper, or Scissors project. What is the difference between userInput === ‘rock’ || userInput ===‘paper’ || userInput ===‘scissors’ and userInput === ‘rock’ || ‘paper’ || ‘scissors’ ? Here is my code:

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

if (userInput === ‘rock’ || userInput ===‘paper’ || userInput === ‘scissors’){

** return userInput;**

} else {

** console.log(‘Error’);**

}

}

console.log(getUserChoice(‘Paper’));

console.log(getUserChoice(‘k’))

Hello!

This will check to see if userInput equals "rock", or if userInput equals "paper" or if userInput equals "scissors".

This will check if userInput equals "rock", or if the string "paper" is a truthy value (which it is), or if the string "paper" is a truthy value (which it is).
The second one will always be true, no matter what userInput is, since if("paper") and if("scissors") will always evaluate to true.

I hope this helps!

1 Like