vendredi 13 mars 2015

JavaScript eval() bug?

I tried to multiply Math.random() by difference of max. value and min. value and then add the min. value... So in theory let's say the Math.random() returns 0.5, max. value is 15 and min. value is 10. Sane person would calculate this as follows: 0.5 * (max - min) + min and get 12.5 but JS returns 2.5 or 250 if you floor/round the Math.rand(). This very strange and unexpected behavior. If someone could explain to me why this happens I would be very glad to read the explanation to this non-sense.



eval("Math.random() * (bubbles[j].xstop - bubbles[j].xstart) + bubbles[j].xstart")


JSFiddle: http://ift.tt/1EipfRu





Aucun commentaire:

Enregistrer un commentaire