Where did my code go wrong


#1

https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/0/4?curriculum_id=506324b3a7dffd00020bf661#

SyntaxError: Unexpected token <=


var userChoice = prompt("do you choose rock, paper or scissors?");

var computerChoice = Math.random("rock" + "paper" + "scissors");

console.log(computerChoice);

if (computerChoice <= 0.33) {
    console.log ("computer chose rock");
    }
else if (computerChoice >= 0.34 && <= 0.66) {
    console.log ("computer chose paper");
    }
else (computerChoice >=0.6 && <= 1) {
    console.log ("computer chose scissors");
    }

hello i'm sorry for any reposts... i'm just so confused about this... my code is very simple (or at least i'm trying to make it simple) and i just don't know where i went wrong... could someone please explain what i did wrong and how to fix it... thanks in advance (i may not be able to respond back in any alloted time because i do not own a working computer but please work with me i have been stuck on this for 3 months)


#2

Hi @designblaster12784,

Please see the code example below.
In this case your conditional checks have be explicitly called out so that the if statement knows what to check on. So you just had to add what you wanted to check against EG: computerChoice
Great work otherwise :slight_smile:

```
var userChoice = prompt("do you choose rock, paper or scissors?");

var computerChoice = Math.random("rock" + "paper" + "scissors");

console.log(computerChoice);

if (computerChoice <= 0.33) 
{
    console.log ("computer chose rock");
}
else if (computerChoice >= 0.34 && computerChoice <= 0.66) //you must explicitly call what you want to check EG: computerChoice
{
    console.log ("computer chose paper");
}
else (computerChoice >=0.6 && computerChoice <= 1) //you must explicitly call what you want to check EG: computerChoice 
{
    console.log ("computer chose scissors");
    }

`


#3

Take a look at this piece of code:

computerChoice >= 0.34 && <= 0.66

You have to be more specific. From the context, I know that you want to check if computerChoice is >= than 0.34 and <= than 0.66. But the computer can't guess what you want to compare, context does not exist. You need to specify left operand for the second expression:

computerChoice >= 0.34 && computerChoice <= 0.66

The second problem is that you should not specify the condition for the else block.


But, in the else if you know that the condition of if must be false. So, in fact, you need condition with only one expression:

if (computerChoice <= 0.33) {
    console.log("computer chose rock");
} else if (computerChoice <= 0.66) {
    console.log("computer chose paper");
} else {
    console.log("computer chose scissors");
}

#4

THANK YOU!!!!!!!!! OMG this had my brain in knots for such a long time


#5

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