Rock, Paper, Scisssor - Issue JS

Hey Lads, all good?

Could someone give me a hand here? I’ve been stuck to this issue for the last two days, I even rewrote the whole code but for some reason it still accuses that the USERCHOICE on the line 42 is not defined, I opened all th hints are given to us and I still can’t see what’s wrong

Follow below the code but I also attached the screenshots.

Thanks a Million

// User’s Turn

const getUserChoice = userInput => {

userInput = userInput.toLowerCase();

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

return userInput

} else {

console.log('Error');

}

}

// Computer’s Turn

const getComputerChoice = () => {

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

switch (randomNumber) {

case 0:

return ‘rock’;

break;

case 1:

return ‘paper’;

break;

case 2:

return ‘scissors’;

break;

default:

break;

}

}

// Defining a winner

function determineWinne (userChoice, computerChoice) {

if (userChoice === computerChoice) {

return 'All tied, try again';

}

if (userChoice === ‘rock’) {

if(computerChoice === 'paper') {

  return 'Paper, you lost!';

} else {

  return 'You won!';

}

}

}

if (userChoice === ‘paper’) {

if(computerChoice === 'scissors') {

  return 'Scissors, you lost!';

} else {

  return 'You won!';

}

}

if (userChoice === ‘scissors’) {

if (computerChoice === 'rock') {

  return 'Rock, you lost!';

} else {

  return 'You won!'

}

}

//Playing the Game

const playGame = () => {

const userChoice = getUserChoice('Scissors');

const computerChoice = getComputerChoice();

console.log('You threw: ' + getUserChoice);

console.log('The computer threw: ' + computerChoice);

console.log(determineWinner(userChoice, computerChoice));

};

playGame();

Hi,

You’ll have a better chance at people helping out if you format this code (see: [How to] Format code in posts)

I can see some misspelled function calls already so that’s one thing to watch out for.
But in general if you’re getting undefined, you need to set some trail of log statements before to see where the data is not passing through properly (and make sure it’s properly scoped and all that).

Hey toastedpitabread

I’ll take a closer on that.

Thanks a million.

Your issue is that you close the determineWinne (typo by the way) function early.

function determineWinne (userChoice, computerChoice) {
  if (userChoice === computerChoice) {
    return 'All tied, try again';
  }

  if (userChoice === ‘rock’) {
    if(computerChoice === 'paper') {
      return 'Paper, you lost!';
    } else {
      return 'You won!';
    }
  }
} //end of function code block

if (userChoice === ‘paper’) { //not in function so cannot see userChoice
//rest of code

Hey jagking,

Yeah I just saw the end of the function code block misplaced but you called the function’s name typo.

Thanks a million.