views:

86

answers:

2
for( count = 0.01; count <= 0.20; count + 0.01 ) 

Is this valid? Because it seems as soon as I changed it to this from count++, my firefox crashed.

+3  A: 
for( count = 0.01; count <= 0.20; count += 0.01 ) 

You were missing an = operator in the last section of the for loop. Otherwise it would be an infinite loop.

rahul
+1  A: 

If you use this code, you'll get values like

  • 0.060000000000000005
  • 0.11999999999999998

If you really want a predictable count, keep the loop integer, and rescale down to the fractional number you need:

for( count = 1; count <= 20; count++ ) console.log(count/100)

This produces values like 0.06 and 0.12, like you would expect.

Joeri Sebrechts