Math Object

Home Up Math Object Demo Parallel Resistors Calculator Format Iteration 
This Page Format is Obsolete!  Go to new site : http://www.science-ebooks.com/javascript-js.html

This Site will go away in spring of 2016:  Please visit http://www.science-ebooks.com to see NEW SITE!

 

Math Object Demo
Parallel Resistors
Calculator Format
Iteration

series 2 pure

 

Math Object and JavaScript Input Message

This Page Format is Obsolete!  Go to new site : http://www.science-ebooks.com/javascript-js.html

This Site will go away in spring of 2016:  Please visit http://www.science-ebooks.com to see NEW SITE!

 

 

 

The Math object provides additional and more complex mathematical operations than the basic ones (+, -, *, /).  We also show how to input data using Prompt method.  After completion of this page you should be able to program your own special purpose calculator for must 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 the 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 number x to the power of an integer N.

<HTML>
<head>
<TITLE>Simple Script 2</TITLE>
</head>
<Body>
<SCRIPT LANGUAGE = JavaScript>
alert("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>
    

Back to: First JavaScript Program    View Demo of Code  Advance to Parallel Resistors

 

You may have noticed that the calculators that you have seen on the Internet use form not popups to input and output data.  If you wish to learn how to use a form, go to Calculator Format.  This will complicate the lesson and is strictly optional.  


        
Questions or problems regarding this web site should be directed to BilPat4342@AOL.com

Copyright ©2003 Science Ebooks All rights reserved.
Last modified: Monday January 18, 2016.