Getting 'undefined' answear

Hey,
thats my code. but instead of getting “You Won!” or “You Lose!”, The code return “undefined”.


// here the user input his choice
let userChoice = 'rock'.toLowerCase();

// random number for the computer choice
let compRandomNumber = Math.floor(Math.random() * 3);

//Computer choice.
let compChoice = () =>  { 
switch(compRandomNumber) {
  case 0: 
    return 'scissors';
  break;
  case 1: 
    return 'rock';
  break;
  case 2: 
    return 'paper';
  break;
}};

console.log(compChoice())



// takes the choices of the User and the Computer, and cheecking who is the winner
let comprasion = () => {
if( userChoice === 'rock' && compChoice === 'scissors') {
  return 'You Won!';
} else if(userChoice === 'paper' && compChoice === 'rock') {
  return 'You Won!';
} else if(userChoice === 'scissors' && compChoice === 'paper') {
  return 'You Won!';
} else if(userChoice === 'scissors' && compChoice === 'rock') {
  return 'You Lose!';
} else if(userChoice === 'rock' && compChoice === 'paper') {
  return 'You Lose!';
} else if(userChoice === 'paper' && compChoice === 'scissors') {
  return 'You Lose!';
} else if(userChoice  === compChoice){
  return 'Teko!';
}
};


//that line  calling the function for decalearing the winner. 
console.log(comprasion());

I didnt cheecked if if the user input is rock\scissors\paper, but I purposly did it.

Thanks,

When things go wrong you’ll usually want to start making observations on what happened to get there. You could for example print out values that your result depends on to find out whether it’s got the value you expect.

1 Like