4/9 part 2 SyntaxError: Unexpected token {


#1

var userChoice = prompt("Do you choose rock, paper or scissors?")
var computerChoice = Math.random()

if (0 <= computerChoice <= 0.33) {
computerChoice = "Rock";
}

else if (0.34 <= computerChoice <= 0.66) {
computerChoice = "Paper";
}

else (0.67 <= computerChoice <= 1) {
computerChoice = "Scissors";
}

I keep getting a "SyntaxError: Unexpected token {
Help?


#2

Your if statement is a little weird. It should be something like:

if(computerChoice <= 0.33){

not

This does not make sense, and gives a syntax problem.

else if(computerChoice<=0.67){

not

ALSO:

THIS MAY BE THE MAIN PROBLEM
There should be no requirements for the else statement, so it should be something like:

else{


#3

The crucial thing is that these "double condition" actually don't cause a syntax problem, they just don't behave as you might expect it, wrote a longer explanation over there:
https://www.codecademy.com/forum_questions/51fc4178f10c60f4eb001233#answer-529f101f7c82ca3ce100308d


#4

Hope this helps:


#5

The conditions seem to be ok, but the task is to assign the strings to computerChoice and not to console.log them.


#6

excuse me sir i dont understand at

the exercise is between 0.33 and 0.67, why is your statement just <= 0.67?


#7

@webjumper49534 It's because you already put that if computerChoice was lower than 0.33, it would become the first option. So, there's no need to do both 0.33 and 0.67, for the numbers that are lower than 0.33 would have already gone down to the first option before the other numbers go on to the next option.:smiley:


#8

i got it, thankyou so much


#9

Your code is missing a semicolon after Math.random();

var userChoice = prompt("Do you choose rock, paper or scissors?")
var computerChoice = Math.random()