Maths not correct?


#1


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";
};


#2

Not possible in JavaScript to make double comparison.

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

#3

@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.


#4

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