Rock, Paper, Scissors project

Hey, why is my output undefined rather than a random number 0-3.

const getUserChoice = userInput => { 
  userInput = userInput.toLowerCase();
if(userInput === 'rock' || userInput === 'paper' || userInput === 'scissors'){
  return userInput;
} else {
  console.log('error, please type either rock, paper, or scissors');
}
// if use return instead of console.log then undefined would not appear
}
// console.log(getUserChoice('jack'));

// now computer has to make choice 

const getComputerChoice = () => {
  const randomNumber = Math.floor(Math.random() * 3);
};

console.log(getComputerChoice());



Hello, @beta7778212385. Welcome to the forums.

Your function doesn’t explicitly return anything, so it implicitly returns undefined.

1 Like