Rock, Paper, Scissors Project

Hi All,
Shall I get some of your help pls? I m stucked in the middle when I follow the steps to build up the code, however it has error like this. Would you mind giving a check on my code below and advise how I could make it running pls? appreciate your help!

Best,
Tre

if (userChoice === “rock”) {
*** ^***

ReferenceError: userChoice is not defined
*** at determineWinner***

const getUserChoice = (userInput) => {
userInput = userInput.toLowerCase();
if (
userInput === “rock” ||
userInput === “paper” ||
userInput === “scissors”
) {
return userInput;
} else {
console.log(“Error! Not good input”);
}
};

function getComputerChoice() {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return (ComputerChoice = “rock”);

case 1:
  return (ComputerChoice = "paper");

case 2:
  return (ComputerChoice = "scissors");

}
}

function determineWinner(UserChoice, ComputerChoice) {
if (UserChoice === ComputerChoice) {
return “it is tie!”;
}

if (userChoice === “rock”) {
if (ComputerChoice === “paper”) {
return “Computer Won!”;
} else {
return “User won!”;
}
}

if (userChoice === “paper”) {
if (ComputerChoice === “scissors”) {
return “Computer Won!”;
} else {
return “User won!”;
}
}

if (userChoice === “scissors”) {
if (ComputerChoice === “rock”) {
return “Computer Won!”;
} else {
return “User won!”;
}
}
}

console.log(determineWinner(“paper”, “scissors”));

//console.log(getComputerChoice());

Hey, welcome to the forums.

It’s just capitalization. You put userChoice instead of UserChoice.

And don’t forget to format your code: [How to] Format code in posts

Thanks a lot, it works now! yes I will have a look on the guide!
appreciated for ur quick help!

1 Like