Unexpected token {



var userChoice = prompt("Do you choose rock, paper, or scissors?")
var computerChoice = Math.random()
if (computerChoice === (0, .33){
    computerChoice = ("Rock");
} else if (computerChoice === .34, .66){
    computerChoice = ("Paper");
} else (computerChoice === .67, 1){
    computerChoice = ("Scissors");


Bracket mismatch is throwing the error. But even it that error wasn't thrown, the above would still raise an error. JavaScript doesn't have tuples, and neither does it have range capability.

If we start from the smallest and work up to the largest, we can use two simple if statements:

if (computerChoice <= 0.33) {
    computerChoice = "rock";
} else if (computerChoice < 0.67) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";


thank you for your quick response!


The first time I read this, I clicked back in anger thinking that you were wrong. Now I understand your clever solution and see that you are right. 'If' statements function like a waterfall, where it only checks the input against the later conditions if the prior conditions have not been met.

I was looking to do this:

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice >= 0 && <=.33) {
computerChoice = "rock";
else if (computerChoice >=.34 && <=.66) {
computerChoice = "paper";
else (computerChoice >=.67 && <=1) {
computerChoice = "scissors";

but keep getting "Unexpected token <=". I'm thinking that this is an indicator that the operator && is being used incorrectly or does not exist in Javascript.


Figured out that this was incorrect because there is nothing to specify on an "else" statement since "else" encompasses everything that does not meet the previous conditions. Silly me.