<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Лабораторная работа 6. Задание 2</title>
<script>
function calculate() {
var r = Number(document.form1.radius.value);
var h = Number(document.form1.height.value);
var body = document.form1.bodyType.value;
var answer;
if (r <= 0 || h <= 0 || isNaN(r) || isNaN(h)) {
alert("Введите радиус и высоту");
return;
}
if (body == "cylinder") {
answer = Math.PI * Math.pow(r, 2) * h;
document.form1.area.value = "Объем цилиндра: " + answer.toFixed(2);
}
if (body == "cone") {
answer = (1 / 3) * Math.PI * Math.pow(r, 2) * h;
document.form1.area.value = "Объем конуса: " + answer.toFixed(2);
}
}
</script>
</head>
<body bgcolor="#f8f8ff">
<center>
<h3>Нахождение объема цилиндра и конуса</h3>
<form name="form1">
<p>Введите радиус:</p>
<input type="text" name="radius" size="10">
<p>Введите высоту:</p>
<input type="text" name="height" size="10">
<p>Выберите тело:</p>
<input type="radio" name="bodyType" value="cylinder" onclick="calculate()"> Цилиндр<br>
<input type="radio" name="bodyType" value="cone" onclick="calculate()"> Конус<br>
<br>
<textarea name="area" cols="40" rows="5"></textarea>
<br><br>
<input type="reset" value="Очистить">
</form>
</center>
</body>
</html>