Else statement returning as Undefined

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

if(userInput === ‘rock’|| userInput===‘paper’ || userInput === ‘scissors’) {
return userInput;
} else {
console.log(‘Error!’);
}

};

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

Hey there @skpessoa and welcome to the forums :grinning:

In the future please look at formatting your code as it preserves indentation, and makes it easier to read or copy/paste.

To format simply press this button:

And then insert your code between the two rows of backticks:


You call your function as the argument for console.log(), since the else block has no return than the console.log() gets a value of “undefined”

1 Like

Okay noted, and thanks for the help

2 Likes