Rock Paper Scissors Exercise

Hey so this is my code :
https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-functions/projects/rock-paper-scissors-javascript

Question is why can I not use userInput === rock || paper || scissors intead of using userInput for each case .

P.S. This is my first time asking a question so any advice is welcomed :slight_smile:

Simple answer: the language doesn’t allow it. They don’t have much reason too, there are other ways to achieve the same thing.

But let’s look at what is happening in your desired case.
First it evaluates the userInput === rock that will be either true or false. If true we are done. If false then it will evaluate paper. If paper isn’t something that evaluates to false, such as undefined, null, 0 an empty string then it will be true, so stop. scissors will be evaluated like paper.

So it’s kind of a 3 partner.

  1. They chose not to allow it when making the language and have decided not to implement it.
  2. That syntax is already valid, so if they did want to implement it they would have to come up with a new syntax to implement it.
  3. Why bother when there are other shorthand ways to evaluate that condition anyway.
1 Like

Hello, @ajax2739326909. Welcome to the forums.

Just FYI, the link you posted does not include your code. It simply goes to the Codecademy lesson. For us to see your code, you can either post it here, by pasting it in following these guidelines, or link to a file that actually contains your code.

1 Like