JAVASCRIPT CONDITIONALS AND FUNCTIONS Rock, Paper, or Scissors

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

I am not sure why when I use console.log to print an error message to the console there is ‘undefined’ underneath the ‘error’. I want to make it go away. can I?

function determineWinner (userChoice, computerChoice) {
  if (userChoice === computerChoice){
    console.log('The result is a tie!');
  }
 // ...
}

Given that there is no return value from the function (it only logs results and terminates) JavaScript returns undefined to the caller, by default.

Then the playGame() function logs the return from the function, undefined.

Since it is logging the return, that means no logging by the function, just returns, such as,

return 'Rock wins!';
1 Like