What am I doing wrong here? Why is my code not running?


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

I seem to be having trouble running this code I started. It seems like the computer isnt running the “computerChoice” variable against the user choice. Any help would be appreciated!

```

var greeting = confirm(“Hi! Do you want to play ROCK PAPER SCISSORS?”);

var firstGame = prompt(“ROCK, PAPER, or SCISSORS?”).toUpperCase();

var computerChoice = Math.floor(Math.random * 12 + 1);{
if (computerChoice <= 4 && computerChoice >= 0){
(computerChoice === ‘ROCK’);
} else if (computerChoice >= 4 && computerChoice <= 8) {
(computerChoice === ‘PAPER’);
} else (computerChoice >= 8 && computerChoice <= 12);{
(computerChoice === ‘SCISSORS’);
}
}

switch (firstGame){

 case 'ROCK':
     if (firstGame === 'ROCK' && computerChoice === 'ROCK'){
         console.log (+ computerChoice + " and ROCK! Tie. ROCK, PAPER or SCISSORS?");
     }
     if (firstGame === 'ROCK' && computerChoice === 'SCISSORS'){
         console.log ( + computerChoice + " loses to ROCK. You win! ROCK, PAPER, or SCISSORS?");
     }
    if (firstGame === 'ROCK' && computerChoice === 'PAPER'){
        console.log (+ computerChoice + " covers rock. You lose! ROCK, PAPER, or SCISSORS?");
    }

}

<do not remove the three backticks above>

#2
var computerChoice = Math.floor(Math.random * 12 + 1);{ // remove {
     if (computerChoice <= 4 && computerChoice >= 0){
         (computerChoice === 'ROCK'); // use assign operator = without ()
     } else if (computerChoice >= 4 && computerChoice <= 8) {
         (computerChoice === 'PAPER'); // just computerChoice = 'PAPER';
     } else (computerChoice >= 8 && computerChoice <= 12);{
         (computerChoice === 'SCISSORS'); // same
     }
 } // remove }

Math.random has wrong syntax. Correct is Math.random(). Also you need to use assign operator = instead of comparison ===.

console.log (+ computerChoice + " and ROCK! Tie. ROCK, PAPER or SCISSORS?");

Remove + before computerChoice.
Also you need to handle PAPER and SCISSORS user choices. So, add these cases in switch statement.


#3

Thank you so much! I appreciate the help!


#4

You are welcome! :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.