Hello
I have a problem with the ternary operator in my function on the “Rock, Paper, Scissors” exercice. I don’t get why it’s returning “undefined” when I’m trying to test it in the console :
function determineWinner(userChoice, computerChoice) {
if (userChoice === computerChoice) {
return 'It\'s a draw !';
} else if (userChoice === 'rock') {
computerChoice === 'paper' ? 'Computer wins' : 'You win !';
} else if (userChoice === 'paper') {
computerChoice === 'scissors' ? 'Computer wins' : 'You win !';
} else if (userChoice === 'scissors') {
computerChoice === 'rock' ? 'Computer wins' : 'You win !';
}
}
console.log(determineWinner('rock', 'paper'));
I guess it’s because we can’t use “return” in a ternary operator, because it’s working just fine if I use the classic if / else structure. But what should I do in a case of a ternary operator ?
Thank you so much for helping me out !