23/04/2016

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

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:-

www.programmingwithbasics.com

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

1 comment: