Maths not correct?

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
the maths just doesn’t work right, it does not ever display paper and after some testing it is practically random within random as to what it will be apart from being paper, I have no idea what is going on



var computerChoice = Math.random();
if (computerChoice < 0.20) {
	computerChoice = "rock";
} else if(0.21 <= computerChoice < 0.40) {
	computerChoice = "paper";
} else if(0.41 <= computerChoice < 0.60){
	computerChoice = "scissors";
} else if(0.61 <= computerChoice < 0.80){
    computerChoice = "lizard";
} else {
    computerChoice = "spock";
};


Not possible in JavaScript to make double comparison.

if (a <= x && x < b) {}

@shaw511 ,

Here and in the other similar lines …

} else if(0.21 <= computerChoice < 0.40) {

… you do not need the lower bound. In each case, that bound was covered by upper bound of the previous conditional block.

In addition to the syntax problem that @mtf identified, there is a gap between each lower bound and the previous upper bound.

Remove all of the lower bounds.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.