Thursday, April 14, 2011

How to perform mathematics openration in Java Script(Math):



A built-in object that has properties and methods for mathematical constants and functions.
Find the power of a number Math.pow(num):
<script language="javascript">

document.write("<h2>How Many bits in 2 bytes?</h2>");
document.write("<h2>Ans:"+Math.pow(2,8)+"</h2");

</script>
Find the square root of a number Math.sqrt(num):
<script language="javascript">

document.write("<h2>what is square root of 200?</h2>");
document.write("<h2>Ans:"+Math.sqrt(200)+"</h2");//power function

</script>
Find out greater number form two numbers Math.max(num1,num2):
<script language="javascript">

document.write("<h2>"+Math.max(10,20)+"</h2>");/*max return the greater number */

</script>
Find out lesser number form two numbers Math.min(num1,num2):
<script language="javascript">

document.write("<h2>"+Math.min(10,20)+"</h2>");//min return the lesser number

</script>
Find out the value of PI constant:
<script language="javascript">

PI=22/7;
document.write("<h2>Value by 22/7="+PI+"</h2>");
document.write("<h2>Value by Math.PI="+Math.PI+"</h2>");
</script>
Find out the value of log base e:
<script language="javascript">

document.write("<h2>Value of log 2 base e="+Math.log(2)+"</h2>");

</script>
Find out the value of Euler constant ex:
<script language="javascript">

document.write("<h2>Value of e<sup>3</sup>="+Math.exp(2)+"</h2>");
</script>

No comments:

Post a Comment