How to do a proper if and else statement for a BMI calculator

function calculateBMI (height, weight){
console.log(height / weight**2);
}
var BMI = calculateBMI(90,1.83);

if (BMI > 20 ){
console.log (‘You need to lose weight’);
}
else {
console.log(‘No problem’)
}

I have put this in the console and it is keeping giving me the else statement not the if statement even though the number is bigger than 20

1 Like

Might you try returning as opposed to logging? Your function result is not making it back to the caller.

What are the units for this calculation? 90 seems like an odd height in metric or imperial, and 1.83 is an awfully strange weight.

The formula is BMI = kg/m2

This would indicate your parameters are reversed.

calculateBMI(weight, height) {
    return weight / height ** 2
}
1 Like