Functions: Rock, Paper or Scissors

I’m a little bit stuck at
https://www.codecademy.com/paths/create-a-back-end-app-with-javascript/tracks/bapi-javascript-conditionals-and-functions/modules/learn-javascript-functions/projects/rock-paper-scissors-javascript.

For the steps 3 to 6, I wrote if/else statements inside getComputerChoice(). Once I printed getComputerChoice(), the terminal gave me paper undefined paper scissors paper

I’m not supposed to get “undefined” according to the hints here, but I have no idea where I went wrong.

I post my code here, could anyone kindly advise me on this?

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

  if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors'){
    return userInput;
  } else if (userInput == 'scissors'){
    console.log('error');
  }
};

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

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

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

  if (randomNumber === 0){
    return 'rock';
  } else if (randomNumber ===  1){
    return 'paper';
  } else if (randomNumber ===  2){
    return 'scissors';
  }
};

console.log(getComputerChoice());
console.log(getComputerChoice());
console.log(getComputerChoice());

Logging functions prints undefined when the function has no return value.

(this is a hint at the issue :slight_smile: )

Hey awkwineh183!
As per @toastedpitabread hint, console.log doesn’t return anything, that’s why you see undefined. Some examples:

"banana";
//output is:
//banana
console.log("banana");
//output is:
//banana
//undefined

So, in your case, when you call the function directly you’ll get the returned value:

getUserChoice('Paper');
//output is:
//Paper

console.log(getUserChoice('Paper'));
//output is:
//Paper
//undefined

Hope this helps :slight_smile: