Write A Complete JavaScript Program To Calculate And Display The Volume Of The Sphere

Write a complete JavaScript program to prompt the user for the radius of a sphere, and call function sphereVolume to calculate and display the volume of the sphere. Use the statement? Volume = ( 4.0 / 3.0 ) * Math.PI * Math.pow( radius, 3 ); to calculate the volume. The user should input the radius through an HTML text field  
And click an XHTML button to initiate the calculation.

Copy Code From Here


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);
alert("Volume= "+vol);
<label>Enter the radius of Sphere: </label>
<input type="text" id="txt" size="30"/><br>
<button onclick="volume()">Find volume</button>



No comments:

Post a Comment