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
Radius.html
<html>
<head><title>pro4</title>
<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);
alert("Volume= "+vol);
}
</script>
</head>
<body>
<label>Enter the radius of Sphere: </label>
<input type="text" id="txt" size="30"/><br>
<button onclick="volume()">Find volume</button>
</body>
</html>
And click an XHTML button to initiate the calculation.
Copy Code From Here
Radius.html
<html>
<head><title>pro4</title>
<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);
alert("Volume= "+vol);
}
</script>
</head>
<body>
<label>Enter the radius of Sphere: </label>
<input type="text" id="txt" size="30"/><br>
<button onclick="volume()">Find volume</button>
</body>
</html>
Output:-
very useful thank you.
ReplyDelete