Kod
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="sectionflex">
<section>
<form>
a <input name="textBox" type="number"><br>
b <input name="textBox" type="number"><br>
r <input name="textBox" type="number"><br>
<input name="wybor" type="radio" value="kwadrat"> kwadrat <br>
<input name="wybor" type="radio" value="prostokat"> prostokąt <br>
<input name="wybor" type="radio" value="kolo"> koło <br>
</form>
</section>
<section>
Pole <br>
<div id="pole"></div>
</section>
</div>
<div class="sectionflex">
<section>
<button id="but">Oblicz</button>
</section>
<section>
Obwód <br>
<div id="obwod"></div>
</section>
</div>
<script>
// let wybor = document.querySelectorAll('input[name="wybor"]')
let button = document.getElementById("but")
let wynikPole = document.getElementById("pole")
let wynikObwod = document.getElementById("obwod")
button.onclick = () => {
let textBox = document.querySelectorAll('input[name="textBox"]')
let a = textBox[0].value
let b = textBox[1].value
let r = textBox[2].value
// console.log(a, b, r)
let wybor = document.querySelectorAll('input[name="wybor"]')
let wybrano = "nic"
for (let wybory of wybor) {
if (wybory.checked) {
wybrano = wybory.value
// console.log(wybrano)
break;
}
}
if (wybrano === "kwadrat"){
wynikPole.innerText = a*a
wynikObwod.innerText = 4 * a
}
else if (wybrano === "prostokat"){
wynikPole.innerText = a * b
wynikObwod.innerText = 2 * a + 2 * b
}
else if (wybrano === "kolo"){
wynikPole.innerText = Math.PI * (r^2)
wynikObwod.innerText = 2 * Math.PI * r
}
// switch (wybrano) {
// case "kwadrat":
// break
// case "prostokat":
// break
// case "kolo":
// break
// }
}
</script>
</body>
</html>