In: Computer Science
5) Write a JavaScript script that will ask the user to enter in
the length of the side of a
cube. (all the sides of a cube are equal) Based on the value that
is entered by the user
from the keyboard, calculate each of the following and assign your
results to variables.
1. volume of the cube
2. surface area of the cube
3. volume of the largest sphere that could fit in the box.
4. surface area of the largest sphere that could fit in the
box.
5. volume of the space in between the cube and the sphere.
HINT: the largest sphere that could fit in the box will have a
diameter equal to the side
of the cube.
ANOTHER HINT: to find the volume in between the cube and sphere you
should subtract
volumes. in case you forgot the sphere formulas, they are:
volume of sphere = 4/3 Pi r3
surface area of sphere = 4 Pi r2
Your script should output HTML text that displays the results of
your calculations.
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
<html>
<head>Java Script </head>
<script>
function myFunction() {
var key=window.prompt("Enter Length Of Side Of The Cube:");
var pi=22/7;
var volume=key*key*key;
var surface_area=6*key*key;
var temp1=(4/3)*pi*volume;
var temp2=(4/3)*pi*key*key;
var temp3=temp1-temp2;
document.getElementById("1").innerHTML =volume;
document.getElementById("3").innerHTML = temp1;
document.getElementById("2").innerHTML =surface_area;
document.getElementById("4").innerHTML =temp2;
document.getElementById("5").innerHTML =temp3;
}
function myFunction1() {
var x = document.getElementById("center");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
<body onload="myFunction1()">
<center><button onclick="myFunction()">Click me</button></center>
<center>1.Volume:<p id="1"></p></center>
<center>2.Surface Area:<p id="2"></p></center>
<center>3.Volume Of Largest Sphere Fit In Box:<p id="3"></p></center>
<center>4.Surface Area Of Largest Sphere Fit In Box:<p id="4"></p></center>
<center>5.Volume Of space in B/w Cube And Sphere:<p id="5"></p></center>
</body>
</html>
Kindly revert for any queries
Thanks.