Project Issue - Rock Paper Scissors - "Undefined"

When I used the following code and log console.log(getComputerChoice()); - a correct value is logged to the console, and then I also get “undefined”. Can someone tell me why I’m also getting an undefined value?

const getComputerChoice = () => {
const randomNumber = Math.floor(Math.random()*3)
switch (randomNumber) {
case 0:
return console.log(‘rock’)
case 1:
return console.log(‘paper’)
case 2:
return console.log(‘scissors’)

Hello, and welcome to the forums!

console.log() doesn’t return a value, so it will always be undefined if you try to return it. You should be returning the string itself. The correct value being logged to the console is only because the function itself is also logging, but it’s only returning undefined.

You could prove this by testing:

const computerChoice = getComputerChoice();
console.log('The computer move is ', computerChoice);

With your current code, it would print The computer move is undefined since that’s what your function is returning.