Why do I get an "undefined" after the expected result?

Greetings, I’m currently doing the rock, paper, scissors mini project. when I type an accepted parameter, the code works as expected, but when i type anything different, it displays the message I want it to, but also the word “undefined”, why?

const getUserChoice = (userInput='') =>{ userInput = userInput.toLowerCase(); if (userInput==='piedra'){ return userInput } else if (userInput==='papel'){ return userInput } else if (userInput==='tijeras'){ return userInput } else{ return console.log('Porfavor escoge una de las opciones o asegurate de haberla escrito de manera correcta'); } } console.log(getUserChoice('pied'));

because here:

return console.log('Porfavor escoge una de las opciones o asegurate de haberla escrito de manera correcta');

you use console.log(), which has no return value (undefined), which you log when you call getUserChoice

1 Like