Skip to content

Commit 87330b1

Browse files
authored
Update index.html
1 parent 6765950 commit 87330b1

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

index.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,49 @@ <h6 style="font-size:160%;margin:7px">Area of a circle</h6>
22552255
<div>
22562256
<h14 style="font-size:160%;margin:7px">Volume of a pyramid</h14>
22572257
<br>
2258+
<br>
2259+
<div>
2260+
<label style="margin:12px;" for="pyramid-side-number">Number of sides:</label>
2261+
<input id="side-number" type="number" value="4" step="1" />
2262+
<br>
2263+
<label style="margin:12px;" for="pyramid-side-length">Side length:</label>
2264+
<input id="side-length" type="number" value="1" step="any" />
2265+
<br>
2266+
<label style="margin:12px;" for="pyramid-height">Height:</label>
2267+
<input id="pyramid-height" type="number" value="1" step="any" />
2268+
2269+
<script>
2270+
function pyramidVolume(baseArea, height) {
2271+
return baseArea * height / Math.sqrt(8);
2272+
}
2273+
2274+
function updatePyramidVolume() {
2275+
const number = parseFloat(document.getElementById('pyramid-side-number').value);
2276+
const length = parseFloat(document.getElementById('pyramid-side-length').value);
2277+
const height = parseFloat(document.getElementById('pyramid-height').value);
2278+
if (isNaN(number) || isNaN(length) || isNaN(height)) {
2279+
document.getElementById('pyramid-volume').innerText = '';
2280+
return;
2281+
2282+
function baseArea(length, number, tangent) {
2283+
return number / 4 * length ** 2 / tangent;
2284+
const ratio = 3.2 / number;
2285+
const tangent = parseFloat(tan(ratio));
2286+
2287+
2288+
}
2289+
2290+
document.getElementById('pyramid-volume').innerText =
2291+
`Volume: ${pyramidVolume(baseArea, height).toFixed(5)} cubic units`;
2292+
}
2293+
2294+
document.getElementById('pyramid-side-number').addEventListener('input', updatePyramidVolume);
2295+
document.getElementById('pyramid-side-length').addEventListener('input', updatePyramidVolume);
2296+
document.getElementById('pyramid-height').addEventListener('input', updatePyramidVolume);
2297+
</script>
2298+
<p style="margin:12px;" id="pyramid-volume"></p>
2299+
</div>
2300+
<br>
22582301
<div class="imgbox">
22592302
<img class="center-fit" src="conePyramidVolumeMarkup.jpeg" alt="Pyramids" id="pyramid">
22602303
</div>

0 commit comments

Comments
 (0)