The computer threw rock and I threw scissors, I won (?)

I have a problem with a javascript project (rock, paper and scissors), when I threw scissors and the computer threw rock, it returns that I won when it would have to be the opposite I think, here’s my code:

const getUserChoice = userInput => {
  userInput = userInput.toLowerCase();
  if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
    return userInput;
  } else {
      console.log("Error!");
    }
};
const getComputerChoice = () => {
 let randomNumber = Math.floor(Math.random() * 3)  
 switch (randomNumber){
    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 = () => {
  const userChoice = getUserChoice ('scissors');
  const computerChoice = getComputerChoice();
  console.log('You threw: ' + userChoice);
  console.log('The computer threw: ' + computerChoice);
  console.log(determineWinner(userChoice, computerChoice));
};
playGame();

I would greatly appreciate your help

1 Like

Check out my comments to your code. Your code will have the user win every single time regardless of what the computer chooses due to what’s missing :wink:

1 Like

Thank you my friend, I was finally able to finish this project thanks to your help, grateful again

4 Likes