Rock paper scissor project

I reviewed the entire section again, ensuring I didn’t misread or misunderstand anything. But still, I’m unable to make the game progress beyond the second block, and I’m completely stumped. Your assistance would be greatly appreciated.

console.log(‘hi’);
//user input for game
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (getUserChoice === ‘rock’ || getUserChoice === ‘paper’ || getUserChoice === ‘scissors’){
return getUserChoice
} else {
return(‘Error please choose rock, paper, or scissors. Thank you.’);
}
}
//computer input for game
const getComputerChoice = Math.floor(Math.random() * 3);

switch(getComputerChoice) {
case 0:
console.log(‘rock’);
break;
case 1:
console.log(‘paper’);
break;
case 2:
console.log(‘scissors’);
break;
}

// section is to pick a winner

function determineWinner(userChoice, computerChoice) {
if (userChoice === computerChoice) {
return ‘Game is a tie!’;
}
if (userChoice === ‘rock’){
if (computerChoice === ‘paper’)
return ‘The computer has won. Please try again!’;
else {
return ‘Player has won! Congratulations!!’;
}
}
if (userChoice === ‘paper’){
if (computerChoice === ‘rock’){
return ‘The Player has won. Congrataulations!’
}else if (computerChoice === ‘scissors’){
return ‘The coputer has won. Please try again!’;
}
}
if (userChoice === ‘scissors’) {
if( computerChoice === ‘paper’){
return ‘Player has won! Congatulations!’
} else
return ‘The computer has won. Please try again’
}
}
//section starts the game
const playGame = () => {
let getUserChoice = userChoice();
let getComputerChoice = computerchoice ();
console.log(You threw + userChoice);
console.log(Computer threw + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
}

In your getUserChoice function, the parameter was userInput, but you used getUserChoice as a variable inside the function (instead of userInput).

Also, you need to redo the getComputerChoice function. You have that as a number variable, not a function in your code. And you’d need to have return inside of that function instead of console.log

In the playGame function,
if getComputerChoice is a function, and computerChoice is the variable that should store the result of calling that function,
then
let getComputerChoice = computerchoice ();
should be
let computerChoice = getComputerChoice();

Don’t forget to check the { and } after you make changes to your code.

Next time, please use the </> button and paste your code on lines between the ``` and ```
so that your code keeps its formatting in the post.

1 Like

Thank you so much for the corrections and the advice; it was helpful and appreciated.