double frick!

Copy and paste the following code into the address bar of your browser, and press enter:

javascript:if (.2 + .4 == .6) alert("frick!"); else alert("double frick!");

The code basically says, “If .2 + .4 is equal to .6, then pop up a window with the message, ‘frick!,’ otherwise, pop up a window with the message, ‘double frick!’” I didn’t learn this until yesterday, but the problem is that floating-point data types don’t always store exact values, but approximations of them, so the “wrong” pop up appears.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>