Rock, scissors, paper exercise into JavaScript introduction

Dear all,

At the point 11 in the exercise mention in the subject of this post, we are asked to test whether the computer logs the right outcome given some example input:

console.log(determineWinner(‘rock’, ‘paper’));
console.log(determineWinner(‘paper’, ‘paper’));
console.log(determineWinner(‘paper’, ‘rock’));

WRT the last, it logs me “undefined”. In fact, in out conditionals we did not include the case where the user picks ‘paper’ and the computer ‘rock’, but only viceversa. The log ‘undefined’ is what I would expect, but I see that the same exact program works perfectly fine in the video, regardless of the order of appearance in the console.log.
What do I do wrong? Thank you very much!!

Hello!
Within your functions, do you return the winner, or do you console.log the winner? If you use console.log, and don’t have a return, then, since the function does not return anything, there is nothing to print. However, JS automatically returns undefined from any function that does not explicitly return anything. So, these console.log statements:

as well as calling the determineWInner function, also print the value that was returned from the function-undefined.
I hope this helps!

1 Like