'Rock Paper Scissors' Exercise - only returning my 'tie' result

Hi!

I’m working on the Rock Paper Scissors project, and I’ve gone all the way through it and managed to make it work…except that the only result determineWinner() will pull is my ‘tie’ condition, regardless of the order I have the conditions listed. Would someone be willing to take a look at it and give me some guidance? I am so confused!

// This is the User’s choice

const getUserChoice = userInput => {

userInput.toLowerCase();

if (userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’ || userInput === ‘bomb’) {

return userInput

} else {

return 'ERROR! ERROR! ERROR!'

}

}

//This is the computer’s choice

const getComputerChoice = () => {

const randomNumber = (Math.floor(Math.random() * 3))

switch(randomNumber) {

case 0:

return 'rock';

case 1:

return 'paper';

case 2:

return 'scissors';

}

}

//This is the winner

const determineWinner = (userChoice, computerChoice) => {

if (userChoice === computerChoice) {

return 'Are you cheating? That is a tie. Try again!'

}

if (userChoice === ‘bomb’) {

return 'LOOK OUT! IT\'S A BOMB!!'

}

if (userChoice === ‘rock’) {

if (computerChoice === 'paper') {

  return 'You\'ve been smothered. Try again.';

  } else {

    return 'You CRUSH THEM! Congratulations!';

  }

}

if (userChoice === ‘paper’) {

if (computerChoice === 'rock') {

  return 'You smother them! Congratulations!';

} else {

  return 'They cut you to ribbons. Try again';

}

}

if (userChoice === ‘scissors’) {

if (computerChoice === 'paper') {

  return 'You cut them to ribbons! Congratulations!';

} else {

  return 'They crush you. Try again!';

}

}

}

// This is the code to play the game.

const playGame = () => {

const userChoice = getUserChoice(‘bomb’);

const computerChoice = getComputerChoice();

console.log('You chose: ’ + userChoice + ‘.’);

console.log(‘The computer chose: ’ + computerChoice +’.’);

determineWinner(userChoice, computerChoice);

console.log(determineWinner());

};

playGame();

Hi @micro9628581397
Welcome to the forums!

You get the tie because you log the determineWinner function with no arguments to the console. userChoice and computerChoice are both ‘undefined’ and therefore the same.

The determineWinner function returns strings instead of logging them. This function call works, but it has no output. If you log this to the console, it has the expected output.

1 Like

That makes perfect sense. Thank you so much!

1 Like