Rock, Paper, Scissors: User throwing only scissors

When I run the program it only shows the user throwing scissors and I can’t figure out what I’ve missed…

I appreciate your help!

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

const getComputerChoice = () => {
let computerChoice=Math.floor(Math.random() * 3); 
switch (computerChoice) {
      case 0:
        return 'rock';
      case 1:
        return 'paper';
      case 2:
        return 'scissors';
    }
}

const determineWinner = (userChoice, computerChoice) => {
  if (userChoice === computerChoice) {
    return 'The game is a tie!';
  } 

  if (userChoice === 'rock') {
    if (computerChoice === 'paper') {
      return 'The computer won!';
    } else {
      return 'You won!';
    }
  }
  
  if (userChoice === 'paper') {
    if (computerChoice === 'scissors') {
      return 'The computer won!';
    } else {
      return 'You won!';
    }
  }
  
  if (userChoice === 'scissors') {
    if (computerChoice === 'rock') {
      return 'The computer won!';
    } else {
      return 'You won!';
    }
    }
    }
  


const playGame = () => {
let userChoice = getUserChoice('scissors');
let computerChoice = getComputerChoice();
console.log('You threw: ' + userChoice);
console.log('The computer threw:' + computerChoice)
console.log(determineWinner(userChoice, computerChoice));
};

playGame();

You didn’t miss anything – the way the project is written, you have to manually change the value of “userChoice”.

You have:

const playGame = () => {
let userChoice = getUserChoice('scissors');

If you don’t change anything, the user will throw scissors every time you run the program. If you do this:

const playGame = () => {
let userChoice = getUserChoice('paper'); // returns "You threw: paper"

Make sense?

3 Likes

Yes, thank you so much! I can’t believe I forgot that :woman_facepalming:

1 Like