"SyntaxError: Unexpected token '{'. Parse error." " Don't know what to do! help please!


#1

Don't know what to do. Keep getting "SyntaxError: Unexpected token '{'. Parse error."

please help! thank you!!

heres my code:

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

if (0 < computerChoice < 0.33) {
computerChoice === "rock";
}
else if (0.34 < computerChoice < 0.66) {
computerChoice === "paper";
}
else (.67 < computerChoice < 1) {
computerChoice === "scissors";
}


#2

Remove the conditional from else

 (.67 < computerChoice < 1)

There is no condition in an else statement.

Next consider that we cannot use inequality syntax from math in JavaScript logical expressions. There is no such expression in JavaScript...

if ( a < b < c )

We must break this into two operands of a logical operation...

if ( a < b && b < c )

In truth, we needn't go to this much length since we're only dealing with a three-way branch. If we order the branches from lowest to highest, we can simplify the logic to a basic statement:

if ( a < 1/3 ) {}
else if ( a < 2/3 ) {}
else {}

a in the above is computerChoice as generated by Math.random(). We know it will be equal to or greater than zero, so no lower bound test is required. We also know that it cannot be equal to or greater than 1 so no upper bound test is required on the last branch.

Does the number fall within the the lower 1/3 of the sample range? Go with 'rock'. Else, does it fall within the lower 2/3 of the sample range? Go with 'paper', else go with 'scissors. It's that simple.


#3

Thank you!!! You're explanation is very clear and helpful ! Thank you so much!! I really REALLY appreciate you!! :smile: <3