Rock paper excer

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

}
console.log(getUserChoice(‘PAPER’))
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;
}
}
console.log(getComputerChoice())

const determineWinner =(userChoice, computerChoice) => {
if(userChoice === computerChoice){
return " game is tie"
}
if (userChoice === ‘rock’) {
(computerChoice === ‘paper’) {
return ‘computer won’;
}
} else {
return ‘You win’
}
if (userChoice === ‘scissors’) {
(computerChoice ===‘rock’) {
return ‘The computer won’
}
} else {
return ‘You won’
}
if (userChoice === ‘paper’) {
(computerChoice === ‘scissors’) {
return ‘computer won’
}
} else {
return ‘user won’
}
determineWinner()

I am getting an error, I tried many times to review my code with the solution video but was still not able to find the bug. can anyone help me please.

What did you want to do with this part of the code?

if (userChoice === ‘rock’) {
       (computerChoice === ‘paper’) {
   return ‘computer won’;
   }
}

If Statement syntax is broken. It should be like this:

if (condition) {
  statement
}

But you have this:

if (condition) {
     (condition) {
  statement
   }
}
1 Like

I was doing
if (condition && condition )
{statement
getting error than I saw the video and they were showing two if statement together and then a statement.
thanks for help

I getting a big error and can’t understand what is pointing out.

Now I get it. You missed one more if in the code

if (userChoice === "rock") {
    if (computerChoice === "paper") {
      return "Computer won!";
    } else {
      return "User won!";
    }
  }
1 Like

home/ccuser/workspace/javascript_101_Unit_3_v2/rockPaperScissors.js:54
});
^
SyntaxError: Unexpected token )
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)

this error thing is coming up in console. even after putting if

and else should be put inside the first if

if (condition) {

   if (condition2){
       statement2
       }  else {
       statement3
       }
}
1 Like

ohhh yes you are so right that was the bug thank you so much for helping

1 Like