Q:

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

belongs to collection: HTML + Javascript Examples

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:


need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Create A HTML Page Insert A Image And Button In Pa... >>
<< Calculates the Distance Between Two Points X1, Y1,...