I am trying to code a simple BMI calculator that takes in the Height & Weight of a person and gives BMI in a round figure. The formula I used is BMI = (weight)/(height * height)
My issue here is that without initializing the wt and ht variables my code is working fine. This means that
wt = prompt ("Enter your weight");
ht = prompt ("Enter your height");
is working fine without initializing the wt & ht variables with var.
Can someone solve this silly doubt of mine, I would be grateful.
wt = prompt("Enter your weight");
ht = prompt("Enter your Height");
function bmi(wt, ht) {
var bmiCal = (wt) / (ht * ht);
bmiCal = Math.round(bmiCal);
if (bmiCal < 18.5) {
alert("Your BMI is " + bmiCal + "so you are underweight");
}
if (bmiCal >= 18.5 && bmiCal <= 24.9) {
alert("Your BMI is " + bmiCal + "so you are normal");
}
if (bmiCal > 24.9) {
alert("Your BMI is " + bmiCal + " so you are overweight");
}
}
bmi();