Did you know that you can do math problems in the address bar of your browser? Regardless of what browser your using, you can use its address bar to find the answer to an arithmetic problem. For instance, let’s say that you are using Internet Explorer and all of a sudden someone asks you what 54 × 32 is. To figure it out, you type the following into the address bar and then hit the ENTER key:
If you tried it out, you know the answer is 1728. What about the square root of 1728? To figure it out, you could use the following:
Now that you know that Math.sqrt(…) exists, you may be wondering, what other math related functions and constants like this exist. Here is a list of them derived from DevGuru.com:
Euler’s constant and the base of natural logarithms (~2.7183).
The natural log of 10.
The natural log of 2.
The base 10 log of E.
The base 2 log of E.
PI – The circumference of a circle divided by its the diameter.
One divided by the square root of 2.
The square root of 2.
The absolute value of the number X.
The arccosine of X (which must be greater than or equal to -1 and less than or equal to 1) as a value between 0 and PI.
The arcsine of X (which must be greater than or equal to -1 and less than or equal to 1) as a value between -PI / 2 and PI / 2.
The arctangent of X as a value between -PI / 2 and PI / 2.
The arctangent of X / Y as a value between -PI / 2 and PI / 2.
If X is an integer this evaluates to X, otherwise it evaluates to the next integer up.
The cosine of X as a value between -1 and 1.
The value of EX where E is Euler’s constant.
If X is an integer, this evaluates to X, otherwise it evaluates to the next integer down.
The natural log (base E) of X (which must be greater than 0).
Math.max(X, Y, …)
The maximum number of X, Y, and any other parameters that you specify.
Math.min(X, Y, …)
The minimum number of X, Y, and any other parameters that you specify.
The value of XY.
A random number that is greater than or equal to 0 and less than 1.
The rounded value of X. If the fractional portion of the number is less than 0.5, the number is rounded down, otherwise it is rounded up.
The sine of X as a value between -1 and 1.
The square root X (which must be greater than or equal to 0).
The tangent of X.
If you haven’t already guessed it,
alert(...) actually displays whatever you specify in a new dialog box. Believe it or not, you can also assign values to variables and then use those variables later on. Of course, though, you have to do all of this on one line. Here is an example of what I mean by assigning values to variables and then using them later:
If you tried the above code out in your address bar, you now know what my age plus the square root of my age is.