about


Scribe:

chrono

blog

Time

science!

book musings

gov

'punk

missle defense

jams

antiques

cultcha blog


Construct:

scripts & programs

on the town

snaps


Self:

creds (PDF)

key

missive


JavaScript: Math Operations

Javascript can do the basic mathematical operators ( +, - . /). Javascript can express more complex mathematical operations through a single math object. This is the square root:
x = 16;
y = Math.sqrt(x);
document.write(y);

(will display the answer "4")

And here is the sine of x:

z = Math.sin(x);
document.write(z);

will display the answer "-0.2879033166650653")

You can convert a number to a string:

a = x.toString(10);

(will display "16")

You can specify the base:

a = x.toString(16);

("10")

a = x.toString(2);

("10000")