<h1>Arealet av en sirkel</h1> <h3>Input</h3> Radius: <input type="number" id="radius"> <button id="btn">Beregn areal</button> <h3>Resultat</h3> <div id="Areal"></div>
document.getElementById("radius").value
let r = document.getElementById("radius").value
const area_circle = function () { let r = document.getElementById("radius").value; return Math.PI * r ** 2; }
onclick="document.getElementById('Areal').innerHTML = area_circle()"
<script> const area_circle = function () { let r = document.getElementById("radius").value; return Math.PI * r ** 2; } </script>
<button id="btn" onclick="document.getElementById('Areal').innerHTML = area_circle()">Beregn areal</button>
By sverres