Development| HTML| JavaScript| Questions? | Software Development
 

JavaScript pow() method

Some times programmers may need to evaluate the value by the power of some numbers therefore JavaScript provides an in-built function Math.pow().

JavaScript pow() method

                         

Some times programmers may need to evaluate the value by the power of some numbers therefore JavaScript provides an in-built function Math.pow().

Syntax:

Math.pow(x,y);

Math.pow(x,y) returns value of x to the power of y (xy). Where x and y both are required.

In the following example we will describe you the use of Math.pow() method with very simple code. Here in this example code we have created two input boxes into which we will take the values of x and y from the user side.

Description of code:

Take two values x and y from the user and then apply the Math object's method pow() onto it. When user clicks on the button "Show Value" it calls the method callPow() as defined in the JavaScript within our <script></script> tag.

 function callPow(){
   var val= document.getElementById("txt").value;
   var power= document.getElementById("txt2").value;
	alert(Math.pow(val,power));
 }

Here we have taken the values of x and y into the "val" and "power" variables. Full html code for this example is as follows :

<html>
<body>
 <script>
 function callPow(){
   var val= document.getElementById("txt").value;
   var power= document.getElementById("txt2").value;
	alert(Math.pow(val,power));
 }
 </script>
 <div style="background: #cf2255; width:'100%';"
              align="center">
  <font color="#ffffcc" size="12pt">
     <b>Pow Example</b></font>
 </div>
  <center>
  <div style="background: #ffffcc; 
  width:'100%';" align="center">
   Input number :<input type="text" id="txt" value=""/>
    to the power<input type="text" id="txt2" value=""/>
  <button onclick="callPow();">Show Value</button>
  </div>
  </center>
</body>
</html>

Output :

Input numbers into the text boxes :

then click on button "Show Value" to view results.

Calculate 3 to the power 5 (35).

You can also download full HTML code from the following link as given below.

Download Source Code

                         

» View all related tutorials
Related Tags: java javascript c attributes script reference object method sed remove ip attribute node move nat to ref e it alter

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.