Hey there, I'm currently working on a beginner project and could use some assistance. My project involves creating a basic BMI calculator using metric units, but I seem to be encountering issues with rounding numbers. Here is a snippet of my code:
var heightInput = document.querySelector(".height-input-field");
var weightInput = document.querySelector(".weight-input-field");
var calculateButton = document.querySelector(".calculate");
var result = document.querySelector(".result");
var statement = document.querySelector(".result-statement");
var BMI, height, weight;
function calculationFunction() {
height = heightInput.value;
weight = weightInput.value;
BMI = weight / Math.pow(height,2);
result.innerText = Math.round(BMI*100)/100;
if (BMI < 18.5) {
statement.innerText = "Underweight";
document.getElementById('result-color').style.backgroundColor="yellow";
} else if ((BMI > 18.5) && (BMI < 24.9)) {
statement.innerText = "Normal weight";
document.getElementById('result-color').style.backgroundColor="green";
} else if ((BMI > 25) && (BMI < 29.9)) {
statement.innerText = "Overweight";
document.getElementById('result-color').style.backgroundColor="yellow";
} else {
statement.innerText = "Obesity";
document.getElementById('result-color').style.backgroundColor="red";
}
}
calculateButton.addEventListener("click", calculationFunction);
/*
BMI Categories:
Underweight = <18.5
Normal weight = 18.5–24.9
Overweight = 25–29.9
Obesity = BMI of 30 or greater
*/
When I run the code, the result shows as 0: actual "app"
If you can offer any guidance, it would be greatly appreciated. Thanks!