Currently, I am enrolled in an online course where one of the tasks given is to develop a BMI (body mass index) calculator. The objective is to create a program that can calculate a user's BMI and provide them with their specific BMI category based on the result.
In my attempt to tackle this problem, I initially implemented an if statement within my code. However, after testing it out, the validator flagged my solution as incorrect. Could someone kindly review my code to help pinpoint any potential errors?
var interpretation = "";
function bmiCalculator(weight, height) {
var bmi = weight / Math.pow(height, 2);
if (bmi < 18.5) {
interpretation = "Your BMI is " + bmi + ", so you are underweight";
} else if (bmi >= 18.5 && bmi <= 24.9) {
interpretation = "Your BMI is " + bmi +", so you have a normal weight";
} else {
interpretation = "Your BMI is " + bmi + ", so you are overweight";
}
return interpretation;
}