4/8 left-hand error


#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 if (0.67 =< computerChoice =< 1) {
computerChoice = "scissors";
} else {
console.log(">");
}

what is wrong with this code?


#2

I'm pretty sure that the < / > operator needs to be before = so either <= or >= you seem to have done it the wrong way round.

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

#3

Thanks!
It works.
So it matters on what side I put operators.


#4

@szymex731 The order of operators is actually like you'd use them in plain english:

less than or equal to <= 
greater than or equal to >=

@twothirdsafool
Still this code is not correct because javaScript is not able to see the context here:

0.34 <= computerChoice <= 0.66

this would be read as

(0.34 <= computerChoice) <= 0.66
true/false <= 0.66

as true and false have values of 0 and 1 in the end this does the opposite of what you suppose it to do. So rather use the long version 0.34 <= computerChoice && computerChoice <= 0.66 or the even shorter one computerChoice <= 0.66 as the previous case already made sure that the number is bigger than 0.34