Need Help on Rock, Paper, Scissors Project

Hello,

I’m working on the Rock, Paper, Scissors functions project for JS, and I cannot seem to solve this bug. The return always shows usersChoice as Rock, regardless of what I input in the playGame function. I think the issue must be in my getUserChoice function, just not sure what the error is.

Any help would be greatly appreciated, full code below.

const getUserChoice = (userInput) => {
    userInput = userInput.toLowerCase();
    if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors' || userInput === 'bomb') {
      return userInput;
   }  else{
        return console.log("Please use a correct input such as rock, paper, or scissors.");
      }
    };

  const getComputerChoice = (computerInput) => {
    computerInput = Math.floor(Math.random() * 3) + 1;
    if (computerInput === 1){
      return 'rock';
    }
    if (computerInput === 2){
      return 'paper';
    }
    if (computerInput === 3){
      return 'scissors';
    }
    return computerInput;
  };

  const determineWinner = (userChoice, computerChoice) => {
    if (userChoice === computerChoice){
      return console.log('This round is a tie.');
    }
    if (userChoice === 'rock'){
      if (computerChoice === 'paper'){
        return console.log('You lose. The computer wins');
      }
      if (computerChoice === 'scissors'){
        return console.log('You win!!!');
      }
    }
    if (userChoice === 'paper'){
      if (computerChoice === 'scissors'){
        return console.log('You lose. The computer wins');
      }
      if (computerChoice === 'rock'){
        return console.log('You win!!!');
      }
    }
    if (userChoice === 'scissors'){
      if (computerChoice === 'rock'){
        return console.log('You lose. The computer wins');
      }
      if (computerChoice === 'paper'){
        return console.log('You win!!!');
      }
    }
    if (userChoice === 'bomb'){
      return console.log('You just dropped a bomb... and won!!!')
    }
  };

  const playGame = () => {
    const userChoice = getUserChoice('not rock');
    console.log('User chose: '+ userChoice);
    const computerChoice = getComputerChoice();
    console.log('Computer chose: ' + computerChoice);
    determineWinner(userChoice, computerChoice)
  };

  playGame();

In the determineWinner function, you have

      return console.log('This round is a tie.');

do you want to print/log the stuff to the screen/console or do you want to return the string?

If you want to do both, you would do

      console.log('This round is a tie.');  // log it to the screen
      return 'This round is a tie.');  // return the string

Also, you should change some of the ifs to else if
(this is important for dealing with not checking for a winner if you know there’s a tie).

You have a parameter in the getComputerChoice that you don’t use.
You generate a random integer 1 to 3 for computerInput instead of using the parameter

Instead, you could write

  const getComputerChoice = () => {
    const computerInput = Math.floor(Math.random() * 3) + 1;

The code seems fine otherwise.

const getUserChoice = (userInput) => { userInput = userInput.toLowerCase(); if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors' || userInput === 'bomb') { return userInput; } else{ return console.log("Please use a correct input such as rock, paper, or scissors."); } }; const getComputerChoice = () => { let computerInput = Math.floor(Math.random() * 3) + 1; if (computerInput === 1){ return 'rock'; } else if (computerInput === 2){ return 'paper'; } else if (computerInput === 3){ return 'scissors'; } return computerInput; }; const determineWinner = (userChoice, computerChoice) => { if (userChoice === computerChoice){ console.log('This round is a tie.'); } else if (userChoice === 'rock'){ if (computerChoice === 'paper'){ console.log('You lose. The computer wins'); } else if (computerChoice === 'scissors'){ console.log('You win!!!'); } } else if (userChoice === 'paper'){ if (computerChoice === 'scissors'){ console.log('You lose. The computer wins'); } else if (computerChoice === 'rock'){ console.log('You win!!!'); } } else if (userChoice === 'scissors'){ if (computerChoice === 'rock'){ console.log('You lose. The computer wins'); } else if (computerChoice === 'paper'){ console.log('You win!!!'); } } else if (userChoice === 'bomb'){ console.log('You just dropped a bomb... and won!!!') } }; const playGame = () => { const userChoice = getUserChoice('paper'); console.log('User chose: '+ userChoice); const computerChoice = getComputerChoice(); console.log('Computer chose: ' + computerChoice); determineWinner(userChoice, computerChoice) }; playGame();