我的代码问题(IF,ELSE)

时间:2014-10-17 04:34:26

标签: javascript function if-statement

这行代码存在技术问题。 我希望它首先计算BMI而不是确定体重是否超过25告诉患者 他们超重了。如果低于18.5,他们体重不足。 看起来不能正常运作。

var calculate 
var test;
calculate = document.getElementById("answer");
calculate.innerHTML =  (weight/(height*height))* 703;

if(calculate > 25)
{
calculate = document.getElementById("answer06");
calculate.innerHTML = "you are fat";
}
else if(calculate < 18.5)
{
calculate = document.getElementById("answer06");
calculate.innerHTML = "you are to skinny";
}

1 个答案:

答案 0 :(得分:4)

var bmi = (weight/(height*height))* 703;
calculate.innerHTML = bmi;

if(bmi > 25)

<强>更新

var bmi = (weight/(height*height))* 703;
document.getElementById("answer").innerHTML = bmi;

if (bmi > 25)
{
    document.getElementById("answer06").innerHTML = "you are fat";
}
else if (bmi < 18.5)
{
    document.getElementById("answer06").innerHTML = "you are too skinny";
}