On step 3 of this project I tried defining the conditional statements with ternary operators, like so:
userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’ ? userInput : console.log(‘Error: not a possible choice.’);
They are within an arrow function, as suggested by the exercise.
It logs what you would expect in the case of false; but it does not log userInput in the case of true (just undefined).
When I write the normal if/else statement everything logs as it should.
The objective is indeed to log userInput (user input should be either ‘rock’, ‘paper’ or ‘scissors’) if true, and error message if false.
I simply tried to practice using ternary operators instead of a normal if/else statement. The if/else statement valid cases correctly with no ‘undefined’ being logged, so I’m assuming I must be making some syntax mistake in the ternary syntax, but I can’t phantom what.
After your question, I’ve also decided to include the keyword return after the question mark, like so ? : return userInput (but that gives an error).
Did I explain what you were asking me for in any of the 3 points above?
Thanks!
Roy, you’re a life saver. So that was my mistake. I was influenced by the syntax of the normal if/else, since the return is included in the codeblock and not at the beginning. Thank you so much. It all works now as it should.