Rock, Paper, Scissor Project

Hello everyone,

This code keeps giving me a Syntax Error, and I don’t know why. Any help will be appreciated:

const getUserChoice = userInput => {
  
  userInput = userInput.toLowerCase();
  
  userInput === 'rock' || userInput === 'paper' || userInput === 'scissors' ? return userInput : console.log('Please, register a valid input. Thanks!');
}

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

Hey there, @array2617608420. Welcome to the forums!


Uncaught SyntaxError: expected expression, got keyword ‘return’

So from this error, we know that there’s an issue around the return keyword.
That’s where we’ll want to investigate.

If the return keyword isn’t accepted where you placed it, and considering that we are inside a function, where else could we possibly put it? What is, exactly, that we’re trying to return?

Hint: putting a console.log inside of your ternary isn’t necessary, since you’re already using console.log outside of your function, to log its result.

1 Like

Thanks. Your reply got me thinking. Here’s the code that works:

const getUserChoice = userInput => {
  
  userInput = userInput.toLowerCase();
  
  return userInput === 'rock' || userInput === 'paper' || userInput === 'scissors' ? userInput : 'Please, register a valid input. Thanks!';
}

console.log(getUserChoice('Rook'));
1 Like

Perfect!

1 Like