Why am i getting undefined?

Greetings, not sure where my undefined is coming from? I need extra eyes please? I am Coded’out!

const getUserChoice = (userInput) => {
  userInput = userInput.toLowerCase();
  if (
    userInput === "rock" ||
    userInput === "paper" ||
    userInput === "scissors" ||
    userInput === "bomb"
  ) {
    return userInput;
  } else {
    console.log("Error!");
  }
};

const getComputerChoice = () => {
  let random = Math.floor(Math.random() * 3);
  switch (random) {
    case 0:
      console.log("rock");
      break;
    case 1:
      console.log("paper");
      break;
    case 2:
      console.log("scissors");
      break;
  }
};

const determineWinner = (userChoice, computerChoice) => {
  if (userChoice === computerChoice) {
    return "Tie";
  }

  if (userChoice === "rock") {
    if (computerChoice === "paper") {
      return "Computer won!";
    } else {
      return "You won!";
    }
  }

  if (userChoice === "paper") {
    if (computerChoice === "scissors") {
      return "Computer won!";
    } else {
      return "You won!";
    }
  }

  if (userChoice === "scissors") {
    if (computerChoice === "rock") {
      return "Computer won!";
    } else {
      return "You won!";
    }
  }

  if (userChoice === "bomb") {
    return "Nuked, you win!";
  }
};

const playGame = () => {
  let userChoice = getUserChoice("paper");
  let computerChoice = getComputerChoice();
  console.log(
    `You played: ${userChoice} and the computer played: ${computerChoice} `
  );
  // console.log(`The computer threw: ${computerChoice}`);

  console.log(determineWinner(userChoice, computerChoice));
};

playGame();

Hey @livnluv great job on coding this! Looks like your switch statements is using console.log instead of return the expected value

const getComputerChoice = () => {
  let random = Math.floor(Math.random() * 3);
  switch (random) {
    case 0:
      console.log("rock"); //return 'rock';
      break;
    case 1:
      console.log("paper"); //return 'paper';
      break;
    case 2:
      console.log("scissors");  //return 'scissors';
      break;
  }
};
1 Like