abs() : Returns the absolute value of a number
<script type="text/javascript">
var s;
var v1 = Math.abs(6);
var v2 = Math.abs(-6);
if (v1 == v2) {
document.write("Absolute values are the same.");
}
else {
document.write("Absolute values are different.");
}
</script>
ceil() : Returns the smallest integer greater than or equal to the number
<script type="text/javascript">
var value = Math.ceil(45.95);
document.write("First Test Value : " + value );
var value = Math.ceil(45.20);
document.write("
Second Test Value : " + value );
var value = Math.ceil(-45.95);
document.write("
Third Test Value : " + value );
var value = Math.ceil(-45.20);
document.write("
Fourth Test Value : " + value );
</script>
floor() : Returns the largest integer less than or equal to a number
<script type="text/javascript">
var value = Math.floor(45.95);
document.write("First Test Value : " + value );
var value = Math.floor(45.20);
document.write("
Second Test Value : " + value );
var value = Math.floor(-45.95);
document.write("
Third Test Value : " + value );
var value = Math.floor(-45.20);
document.write("
Fourth Test Value : " + value );
</script>
max() : Returns the greater of two numbers
<script type="text/javascript">
document.write(Math.max(0,150,30,20,38));
</script>
min() : Returns the lesser of two numbers
<script type="text/javascript">
document.write(Math.min(0,150,30,20,38));
</script>
pow() : Returns base if the exponent power, that is baseexponent
<script type="text/javascript">
document.write(Math.pow(10,3));
</script>
random() : Returns a pseudo-random number between 0 and 1
<script type="text/javascript">
document.write(Math.random());
//Get a random number between 1 and 6
document.write(Math.floor(Math.random() * 6) + 1);
//Get a random number between 1 and 10
document.write(Math.floor((Math.random()*10)+1);
</script>
round() : Returns the value of a number rounded to the nearest integer
<script type="text/javascript"> document.write(Math.round(25.9)+"
"); document.write(Math.round(25.4)+"
"); document.write(Math.round(25.5)+"
"); document.write(Math.round(-2.58)); </script>
sqrt() : Returns the squareroot of a number
<script type="text/javascript">
document.write(Math.sqrt(16));
document.write(Math.sqrt(3));
</script>
<script type="text/javascript">
var n = prompt("Please Enter a Number.");
var n1 = parseInt(n);
if (isNaN(n1)) {
alert(n1);
}
var e = eval(2 + n1);
alert(e);
</script>
<script type="text/javascript">
r = 5;
theta = 60;
beta = 45;
with (Math) {
a = PI * r * r;
y = tan(theta);
x = r * cos(theta);
z = abs(beta);
alert(a + ":" +y+":"+x+":"+z);
}
is the functional equivalent of:
a = Math.PI * r * r;
y = Math.tan(theta);
x = r * Math.cos(theta);
z = Math.abs(beta);
</script>
| After editing Click here: |
Output:
|