SyntaxError: Unexpected token { ,


#1

Can any one tel me why am getting the error ?SyntaxError: Unexpected token {. Below is my code. Not getting what is the error . Please help

var userChoice=prompt("Do you choose rock,paper or scissors?");
var computerChoice=Math.random();
console.log(computerChoice);
if(computerChoice <=0.33){
computerChoice="rock";
}
else if(0.34 >= computerChoice <=0.66){
computerChoice="paper";
}
else(0.67 >=computerChoice <=1){
computerChoice="scissors";
}


#2

This is why...

else has no conditional parameter. It is a default code block:

    } else {
       // ...
    }

#3

This is not valid JavaScript...

There are no 'man in the middle' comparison expressions in JS. only two binaries.

0.34 >= computerChoice && computerChoice <= 0.66

This is still not correct, but it is dialing in. The main point so far is that we have two expressions, each with two operands. The next step will deal with the truthiness of the expressions. Do they make sense and are they true?

The above will only work if computerChoice is less than 0.34, in which case it is also less than or equal to 0.66. The segment it is matching is the 0.01 that the first conditional missed.

We're turning this into logic soup when we could be creating order. A lower bound and an upper bound suggests order. Why not impose that on our logic? It simplifies everything.

// let c = computerChoice for brevity
var a, b, c = computerChoice;
a = 1 / 3;
b = 2 / 3;
if (c < a) {
    //
} else
if (c < b) {
    //
} else {
    //
}
computerChoice = c;