Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a JavaScript script that will ask the user to enter in the length of the s

ID: 3598256 • Letter: W

Question

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 r3 surface area of sphere = 4 r2
Your script should output HTML text that displays the results of your calculations.

Explanation / Answer

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

<center><button>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>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote