Help for rock, paper, scissors project

Hi,
I’d like some help, I don’t know what’s wrong with my code. I get unbelievable results like “paper won scissors lose”. Thank you for your help (sorry for my bad english!!)
:pray: :pray:

console.log(‘Welcome to Rock, Paper, Scissors !’);

let userInput = “”;
userInput = userInput.toLowerCase()

// l’utilisateur choisi pierre, papier ou ciseaux
const getUserChoice = userInput => {
if (userInput === ‘rock’) {
return ‘rock’
} else if (userInput === ‘paper’){
return ‘paper’
} else if (userInput === ‘scissors’){
return ‘scissors’
} else {
return ‘Error ! Enter a choice’;
}
};

// l’ordinateur choisi également
const getComputerChoice = () => {
const rand = Math.floor(Math.random() * 3)
switch (rand){
case 0 :
return ‘rock’;
case 1 :
return ‘paper’;
case 2 :
return ‘scissors’;
}
};

// determiner le gagnant
const determineWinner = (userChoice, computerChoice) => {
// en cas d’égalité
if (userChoice === computerChoice) {
return ‘Equality’
}
// la feuille recouvre le papier
if (userChoice === ‘rock’) {
} if (computerChoice === ‘paper’) {
return ‘Computer win !’
} else {
return ‘User win !’
}
// les ciseaux coupent le papier
if (userChoice === ‘paper’) {
} if (computerChoice === ‘scissors’) {
return ‘Computer win !’
} else {
return ‘User win !’
}
// la pierre casse les ciseaux
if (userChoice === ‘scissors’) {
} if (computerChoice === ‘rock’) {
return ‘Computer win !’
} else {
return ‘User win !’
}
};

const playGame = () => {
const userChoice = getUserChoice(‘paper’);
const computerChoice = getComputerChoice();
console.log(You have chosen ${userChoice});
console.log(Computer choose ${computerChoice} );
console.log(determineWinner(userChoice, computerChoice));
};

playGame();

You have some } in the wrong place.

Immediately after if (userChoice === 'rock') { , you have }, so nothing would be executed in there.
Instead, you want that } after that last else.
The idea is that the if-else stuff for the computer’s choice are inside the if-block for the userChoice

if (userChoice === 'rock') {
  if (computerChoice === 'paper') {
      return 'Computer win !'
  } else {
      return 'User win !'
  }
}

Notice that there is no } immediately before if (computerChoice === 'paper') {

1 Like

Thank youuu!! I will correct this right now :grinning: :grinning: