Uninitialised variables working fine as arguments



I am trying to code a simple BMI calculator that takes in Height & Weight of a person and gives BMI in round figure. The formula I usedis BMI = (weight)/(height * height)

My issue here is that without initialising 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 initialising 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");

Continue reading...