BMI beregner i JavaScript

Her er koden til BMI beregneren

 

<div class="calculator-container">
<h2>Beregn din BMI</h2>
<form>
	  <label for="height">Højde</label><br>
	  <input type="text" id="height" name="height" onfocus="this.value=''" value="Skriv din højde her"><br>
	  <label for="weight">Vægt</label><br>
	  <input type="text" id="weight" name="weight" onfocus="this.value=''" value="Skriv din vægt her">
	</form>
<br>
	<button id="calculateButton">Beregn dit BMI-tal</button></div>
	<p>&nbsp;</p>
	<h3 id="result"> </h3>
	<p>&nbsp;</p>
	<p id="result-statement"> </p>
	<input type ="button" id="btn" value="" onclick =location.reload();></input>

	<p><script>
	var height = document.getElementById('height');
	var weight = document.getElementById('weight');
	var calculateButton = document.getElementById('calculateButton');
	var result = document.getElementById('result');
	var statement = document.getElementById('result-statement');
	var BMI, height, weight;
	var btn = document.getElementById('btn');


	calculateButton.addEventListener("click", ()=>{

		height = height.value;
		weight = weight.value;
	height = height / 100; 
		BMI = weight/(height**2); 
	BMI = Math.round (BMI);


if (isNaN(BMI) === true){
result.innerText = "Udfyld alle felter!";
statement.innerText = "";
btn.value = "Prøv igen";
		}
else

if((BMI < 18.5)){
result.innerText = "Dit BMI-tal er " +BMI;
btn.value = "Ny beregning";
statement.innerText = "Du er undervægtig";
}

else

if ((BMI > 18.5) && (BMI <= 25)) {
result.innerText = "Dit BMI-tal er " +BMI;
btn.value = "Ny beregning";
statement.innerText = "Du er normalvægtig";
}

else

if (BMI == 25) {
result.innerText = "Dit BMI-tal er " +BMI;
btn.value = "Ny beregning";
statement.innerText = "Du er på grænsen til overvægt";
}

else

if ((BMI > 25) && (BMI <= 29.9 )){
result.innerText = "Dit BMI-tal er " +BMI;
btn.value = "Ny beregning";
statement.innerText = "Du er overvægtig";
}

else

if ((BMI >= 30) && (BMI < 34.99 )){
result.innerText = "Dit BMI-tal er " +BMI;
btn.value = "Ny beregning";
statement.innerText = "Fedmeklasse 1";
}

else

if ((BMI >= 35) && (BMI <= 39.99 )){
result.innerText = "Dit BMI-tal er " +BMI;
btn.value = "Ny beregning";
statement.innerText = "Fedmeklasse 2";
}

else

if(BMI >= 40){
result.innerText = "Dit BMI-tal er " +BMI;
btn.value = "Ny beregning";
statement.innerText = "Fedmeklasse 3";
}

	});
	

	</script>
</p>