Kod
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
</head>
<body>
<script type="text/javascript">
// Wartości
document.write("<h3>Wartości:</h3><hr>")
let r = parseInt(Math.random()*100)
let h = parseInt(Math.random()*100)
// Stare ↓
// let r = parseInt(prompt("Podaj promień: ",""));
// let h = parseInt(prompt("Podaj wysokość: ",""));
document.write(`Promień \"r\"= ${r}<br>`);
document.write(`Wysokość \"h\"= ${h}<br>`);
// Kalkulacje
function cone_vol() {
return ((1/3) * Math.PI * (r ** 2) * h);
}
function cone_area() {
const poleBoczne = Math.PI * r * h;
const polePodstawy = Math.PI * Math.pow(r, 2);
return (poleBoczne + polePodstawy);
}
// Odpowiedź
document.write("<h3>Wyniki:</h3><hr>")
document.write(`Objętość stożka = ${cone_vol().toFixed(2)}<br>`);
document.write(`Pole stożka = ${cone_area().toFixed(2)}`);
</script>
</body>
</html>