Need help with rock paper scissors project

this is my code for it and i cant figure out what im missing or got wrong it keeps saying the const play game has a error can anyone help me please
const getUserChoice = userInput => {
userInput = userInput.toLowerCase()};
if(userInput ===‘paper’&&userInput===‘rock’&&userInput ===‘scissors’ && userInput === ‘bomb’){
return userInput;
} else {
console.log(‘Error’);
}

const getComputerChoice = () => {
let num = (Math.random(Math.floor() *3));
switch (num) {
case 0:
return ‘paper’;
break;
case 1:
return ‘rock’;
break;
case 2 :
return ‘scissors’;
break;
}
}
const determineWinner = (userChoice,computerChoice => {
if (userChoice === ComputerChoice)
{ return ‘the game is a tie!’;
}
if (userChoice === ‘rock’){
if(computerChoice === ‘scissors’);
{
return ‘you won’;
}
} else (computerChoice === ‘paper’);{
return ‘computer won’;
}
if (userChoice === ‘paper’){
if(ComputerChoice === ‘rock’){
return ‘you won’
}
else (ComputerChoice === ‘scissors’);{
return ‘computer won’;
}
if (userChoice === ‘scissors’){
if(ComputerChoice === ‘paper’){
return ‘you won’;
}
else (ComputerChoice === ‘rock’);{
return ‘computer won’
}
}
}
}
const playGame = () => {
let getUserChoice= userInput(‘paper’);
let computerChoice = getComputerChoice();
console.log('you Threw: '+ userChoice);
console.log(‘the computer threw:’ + computerChoice);
console.log(determineWinner(userChoice , computerChoice));
}

playGame();

Hiyah.
There’s a few things I’ve spotted which may be causing issues.

  1. Your getUserChoice function.
    It has a closing bracket at the end of the second line - so the if isn’t included in it.
    The If is also checking if the userinput is ‘paper’ AND ‘rock’ AND ‘scissors’ AND 'bomb…

  2. ‘else’ doesn’t want a condition.
    you can have ‘else if’ if it needs to check a condition or
    ‘else’ if it’s for just the code not included in the ‘if’ or ‘else if’ code blocks
    e,g.
    if (a === 1)
    { will run if a = 1 }
    else if (a === 2)
    {will run if a = 2 }
    else
    { will run if a is neither 1 or 2 }

Hope that helps

2 Likes

ok i was able to fix that but i get this message in the message home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:52
const playGame = () => {
^^^^^

  1. Make sure that you have removed any semi colons - if you fixed the comments above to have proper else if statements:

} else (computerChoice === ‘paper’);{
return ‘computer won’;
}

  1. Also the closing brackets in the nested if should behave like this for each userChoice.
if (condition) { if (condition2) { // Do something } else if (condition3) { // Do Something } else { //Do Something } }

I believe these misplaced curly brackets may be causing your issues at the end of the determineWinner function.

2 Likes

thank you guys i was finally able to get it working thanks to your guys awesome advice
here’s the full thing below

const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if(userInput ===‘paper’||userInput===‘rock’||userInput ===‘scissors’ || userInput === ‘bomb’){
return userInput;
} else {console.log(‘Error’);
}
}
console.log(getUserChoice(‘paper’));
const getComputerChoice = (computerChoice) => {
const randomNumber = (Math.floor(Math.random() *3));
switch (randomNumber){
case 0:
return ‘paper’;
break;
case 1:
return ‘rock’;
break;
case 2:
return ‘scissors’;
};
};
console.log(getComputerChoice());
const determineWinner = (userChoice,computerChoice) => {
if (userChoice === computerChoice)
{ return ‘the game is a tie!’;
}
if (userChoice === ‘rock’);{
if(computerChoice === ‘scissors’);
{
return ‘you won’;
}
if (computerChoice === ‘paper’);{
return ‘computer won’;
}
}
if (userChoice === ‘paper’);{
if (ComputerChoice === ‘rock’){
return ‘you won’
}
else if (ComputerChoice === ‘scissors’);{
return ‘computer won’;
}
}
if (userChoice === ‘scissors’);{
if (ComputerChoice === ‘paper’){
return ‘you won’;
}
else if (ComputerChoice === ‘rock’);{
return ‘computer won’
}
}
}
const playGame = () => {
const userChoice = getUserChoice(‘paper’);
const computerChoice = getComputerChoice();
console.log(you Threw: + userChoice);
console.log(the computer threw: + computerChoice);
console.log(determineWinner(userChoice , computerChoice));
}

playGame();

1 Like