Slip 1 - A) Write a JavaScript program to calculate the volume of a sphere.

Solution:

<html>

<script>

function volume()

{

var t_val=document.getElementById("txt").value;

var rad=parseInt(t_val);

var vol=(4.0/3.0)*Math.PI*Math.pow(rad,3);

document.getElementById('volume').value=vol;

}

</script>

</head>

<body>

<table border="1">

<tr><td>Enter the radius of Sphere: </td><td><input type="text" id="txt" size="30"/></td></tr>

<tr><td>Volume</td><td><input type="text" name="volume" id="volume"></td></tr>

<tr><td> </td><td><input type="submit" value="Calculate" onclick="volume()"></td></tr>

</table>

 </body>

</html>


Post a Comment

0 Comments