Rock, Paper or Scissors Project - toLowerCase error

Hi all,
This is my first post on the forum and sorry if it doesn’t follow all the guidelines :).
I am a beginner and I need your help to understand this topic.

I am having the following error when I run my program for the project below:

https://www.codecademy.com/courses/introduction-to-javascript/projects/rock-paper-scissors-javascript ^

TypeError: Cannot read property ‘toLowerCase’ of undefined
at getUserChoice (/home/ccuser/workspace/javascript_101_Unit_3_v2/rockPaperScissors.js:3:24)
at playGame

Below is my code:

`[codebyte]
console.log("Hi");
const getUserChoice = userInput => {
  userInput = userInput.toLowerCase();
  if (
    userInput === "rock" ||
    userInput === "paper" ||
    userInput === "scissors"
  ) {
    return userInput;
  } else {
    console.log("Not a valid Choice");
   }
  };
const getComputerChoice = () => {
  const 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 "This game is a tie";
  }

  if (userChoice === "rock") {
    if (computerChoice === "paper") {
      return "Sorry, the computer won!";
    } else {
      return "Congratulation, you win the game!";
    }
  }

  if (userChoice === "paper") {
    if (computerChoice === "scissors") {
      return "You lost the game!";
    } else {
      return "Congratulation, you won!";
    }
  }

  if (userChoice === "scissors") {
    if (computerChoice === "rock") {
      return "You have lost, sorry!";
    } else {
      return "Well played!";
    }
  }
 };
  
// playgame function
 const playGame = () => {
  const userChoice = getUserChoice('paper');
  const computerChoice = getUserChoice();
  console.log('You threw' + userChoice)
  console.log('The computer threw' + computerChoice)
};
playGame()
//console.log(determineWinner('scissors', 'scissors'))

``[/codebyte]`

I can’t find any solution and the code seems to be working fine up to the point I have declared the playGame function.

What is the reason for this error?

It could be as simple as a missing space character in the above.

I don’t see any missing space characters in the code.

Could you please direct me to the error, I am sure it is something I am overseeing at this point…

'You threw'

vs.

'You threw '

I have found the issue!

there a wrong attribute here

const playGame = () => {
  const userChoice = getUserChoice('paper');
  const computerChoice = getUserChoice();
  console.log('You threw' + userChoice)
  console.log('The computer threw' + computerChoice)
};

const computerChoice = getUserChoice()

I could only find after comparing the lines of code 1000 times tough

1 Like

here is my final code and it is finally working !

console.log("Hi"); const getUserChoice = userInput => { userInput = userInput.toLowerCase(); if ( userInput === "rock" || userInput === "paper" || userInput === "scissors" || userInput === 'bomb' ) { return userInput; } else { console.log("Not a valid Choice"); } }; const getComputerChoice = () => { const 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 "This game is a tie"; } if (userChoice === 'bomb') { return 'You threw a bomb! you won the game' } if (userChoice === "rock") { if (computerChoice === "paper") { return "Sorry, the computer won!"; } else { return "Congratulation, you win the game!"; } } if (userChoice === "paper") { if (computerChoice === "scissors") { return "You lost the game!"; } else { return "Congratulation, you won!"; } } if (userChoice === "scissors") { if (computerChoice === "rock") { return "You have lost, sorry!"; } else { return "Well played!"; } } }; // playgame function const playGame = () => { const userChoice = getUserChoice('bomb'); const computerChoice = getComputerChoice(); console.log('You threw ' + userChoice) console.log('The computer threw ' + computerChoice) console.log(determineWinner(userChoice, computerChoice)) }; playGame()