The Math object provides additional and more complex mathematical operations than the basic ones (+, -, *, /). We also show how to input data using Prompt method (View bottom of page!). After completion of this page you should be able to program your own special purpose calculator for most analog scientific calculations.
Syntax Output
Math.abs(value) Absolute value
Math.acos(value) Arc Cosine in radians
Math.asin(value) Arc sine in radians
Math.atan(value) Arc Cosine in radians
Math.atan2(x,y) Angle of polar coordinates of x, y
Math.ceil(value) Next Integer greater or equal to value
Math.cos(value) Cosine of value. Value input in radians
Math.floor(value) Next Integer less than or equal to value
Math.log(value) Natural Log (base e) of value
Math.max(val1, val 2) The greater of value 1 or value 2
Math.min(val1, val 2) The lessor of value 1 or value 2
Math.pow(val1, val 2) value 1 to the value 2 power
Math.random() Random number between 0 and 1
Math.round(value) rounds to closest integer (n.5000 rounds up).
Math.sin(value) Sin of value (value input in radians)
Math.sqrt(value) Square Root of value
Math.tan(value) Tangent of value (value input in radians)
Prompt method of inputing information:
var text = prompt ("Enter Integer for var N ","")
n = parseInt (text)
Note that the parseInt() statement tells the program to interpret text entered in box as a Integer.
var text = prompt ("Enter decimal number for var x ","")
var x = parseFloat(text)
Note the the parseFloat() statement tells the program to interpret text entered in box as a decimal (floating point) number.
Program below uses both the Math Object and inputs two variables. Copy program to Notepad and then run using Internet Explorer as we did on previous page.
The following program raises a decimal varible x to the to the powe of Integer N.
y1 = x^N
<HTML>
<head>
<TITLE>Simple Script 2</TITLE>
</head>
<Body>
<SCRIPT LANGUAGE = JavaScript>
alert("The MATH OBJECT script has started.")
var text = prompt ("Enter Integer for var N ","")
var n = parseInt(text)
var text = prompt ("Enter decimal number for var x ","")
var x = parseFloat(text)
y1 = Math.pow(x, n)
alert("y1 = " + y1)
</SCRIPT>
</Body>
</HTML>
Syntax Output
Math.abs(value) Absolute value
Math.acos(value) Arc Cosine in radians
Math.asin(value) Arc sine in radians
Math.atan(value) Arc Cosine in radians
Math.atan2(x,y) Angle of polar coordinates of x, y
Math.ceil(value) Next Integer greater or equal to value
Math.cos(value) Cosine of value. Value input in radians
Math.floor(value) Next Integer less than or equal to value
Math.log(value) Natural Log (base e) of value
Math.max(val1, val 2) The greater of value 1 or value 2
Math.min(val1, val 2) The lessor of value 1 or value 2
Math.pow(val1, val 2) value 1 to the value 2 power
Math.random() Random number between 0 and 1
Math.round(value) rounds to closest integer (n.5000 rounds up).
Math.sin(value) Sin of value (value input in radians)
Math.sqrt(value) Square Root of value
Math.tan(value) Tangent of value (value input in radians)
Prompt method of inputing information:
var text = prompt ("Enter Integer for var N ","")
n = parseInt (text)
Note that the parseInt() statement tells the program to interpret text entered in box as a Integer.
var text = prompt ("Enter decimal number for var x ","")
var x = parseFloat(text)
Note the the parseFloat() statement tells the program to interpret text entered in box as a decimal (floating point) number.
Program below uses both the Math Object and inputs two variables. Copy program to Notepad and then run using Internet Explorer as we did on previous page.
The following program raises a decimal varible x to the to the powe of Integer N.
y1 = x^N
<HTML>
<head>
<TITLE>Simple Script 2</TITLE>
</head>
<Body>
<SCRIPT LANGUAGE = JavaScript>
alert("The MATH OBJECT script has started.")
var text = prompt ("Enter Integer for var N ","")
var n = parseInt(text)
var text = prompt ("Enter decimal number for var x ","")
var x = parseFloat(text)
y1 = Math.pow(x, n)
alert("y1 = " + y1)
</SCRIPT>
</Body>
</HTML>
|
|