var weight = parseInt(prompt("What is your weight?"));
var height = parseInt(prompt("What is your height?"));
var bmi;
bmi= weight/ height;
var bmiResult = bmi.toFixed(2);
alert("your weight is" + bmiResult);
if (bmiResult>=30) {
alert("obese");
}
else if (bmiResult>25 || bmi<30) {
alert('overweight');
}
else if (bmiResult>18.5 || bmi<=25) {
alert('normal');
}
else if (bmiResult>=16 || <=18.5) {
alert('underweight');
}
else (bmiResult<16) {
alert('very underweight');
}
此代码似乎不起作用,我无法弄清楚为什么......我正在尝试根据用户输入的权重/高度来获取if / else语句。谁能解释为什么它不起作用?
答案 0 :(得分:1)
您忘记将变量放在运算符<=
下面:
bmi= weight/ height;
var bmiResult = bmi.toFixed(2);
alert("your weight is" + bmiResult);
if (bmiResult>=30) {
alert("obese");
}
else if (bmiResult>25 || bmi<30)
{ alert('overweight');
}
else if (bmiResult>18.5 || bmi<=25)
{ alert('normal');
}
else if (bmiResult>=16 || bmiResult<=18.5) // <== their it is
{ alert('underweight');
}
else (bmiResult<16)
{ alert('very underweight');
}
答案 1 :(得分:1)
else if (bmiResult>=16 || <=18.5)
{ alert('underweight');
}
错误&lt; = 18.5你的意思是|| bmiResult&LT = 18.5