用javascript计算体重指数

用javascript计算体重指数,javascript,html,Javascript,Html,我目前正在创建一个可以用javascript计算体重指数的程序。我不知道为什么,但它工作不正常。我一定错过了什么,但我不确定是什么。如果有人能帮助我,我将非常感激。多谢各位 <!DOCTYPE html> <!-- --> <html> <head> <meta charset="UTF-8" /> <title>Body Mass Index</title> &

我目前正在创建一个可以用javascript计算体重指数的程序。我不知道为什么,但它工作不正常。我一定错过了什么,但我不确定是什么。如果有人能帮助我,我将非常感激。多谢各位

<!DOCTYPE html>
   <!--    -->
<html>

   <head>
      <meta charset="UTF-8" />
      <title>Body Mass Index</title>
   </head>


   <BODY>
    <header><img src="bmi.jpeg" width="380" height="132" border="0" alt="bmi"></header>

<video controls="controls"
width="320px" height="260px">
<source src="bmi.mp4"/>

      <p>When it comes to weight loss, there's no lack of fad diets promising fast results. But such diets limit your nutritional intake, can be unhealthy, and tend to fail in the long run.</p>

      <p>The key to achieving and maintaining a healthy weight isn't about short-term dietary changes. It's about a lifestyle that includes healthy eating, regular physical activity, and balancing the number of calories you consume with the number of calories your body uses.</p>

      <p>BMI is a number calculated from a person's weight and height. BMI provides a reliable indicator of body fatness for most people and is used to screen for weight categories that may lead to health problems.</p>

      <p>The BMI ranges are based on the relationship between body weight and disease and death. 
      Overweight and obese individuals are at increased risk for many diseases and health conditions, including the following:</p>





You need a flash player to view this video.

</video>

      <ul>
        <li>Hypertension</li>
        <li>Dyslipidemia (for example, high LDL cholesterol, low HDL cholesterol, or high levels of triglycerides)</li>
        <li>Type 2 diabetes</li>
        <li>Coronary heart disease</li>
        <li>Stroke</li>
        <li>Gallbladder disease</li>
        <li>Osteoarthritis</li>
        <li>Sleep apnea and respiratory problems</li>
        <li>Some cancers (endometrial, breast, and colon)</li>
     </ul>

<script type="text/javascript">
function CalculateBMI(){
var inch=12;
var ft;
var bmi= Math.write(weight*703)/ (inch height)^2;

if(bmi<=19)
{"Underweight";
}
if else(19<bmi<=25)
{"Desirable";
} 
if else(25<bmi<=29)
{"Prone to health risks";
}
if else (29<bmi<=40)
{"obese"
}
else(40<bmi)
{"Extremely Obese"
} 
}
</script>
     <form name="bmi">


     <p> Weight:<p/></td>  <td><input type="text" id="weight" name="weight" size="25" />


<p>Height:</p> <input type="text" id="textbox" name="textbox" size="25" /><td><p>Ft.</p><input type="text" id="textbox" name="textbox" size="25" /> <p>In.</p>

<input type="submit" id="Calculate BMI" name="Calculate BMI" value="Calculate BMI" size="25" onclick="CalculateBMI()" />
 According to the Panel on 
Energy, Obesity, and Body Weigth Standards published by
American Journal of Clinical Nurttrition, your category is:
<input type="text" id="textbox" name="textbox" size="25" />


     </form>

   </BODY>

</html>

体质指数
当谈到减肥时,不乏能带来快速减肥效果的时尚饮食。但是这样的饮食限制了你的营养摄入,可能是不健康的,而且从长远来看往往会失败

实现和保持健康体重的关键不是短期的饮食改变。它是关于一种生活方式,包括健康的饮食,有规律的体育活动,平衡你消耗的卡路里数量和你身体消耗的卡路里数量

BMI是根据一个人的体重和身高计算出来的数字。BMI为大多数人提供了一个可靠的身体肥胖指标,用于筛选可能导致健康问题的体重类别

BMI范围是基于体重与疾病和死亡之间的关系。 超重和肥胖者患多种疾病和健康状况的风险增加,包括:

您需要一个flash播放器才能观看此视频。
  • 高血压
  • 血脂异常(例如,高LDL胆固醇、低HDL胆固醇或高甘油三酯水平)
  • 2型糖尿病
  • 冠心病
  • 笔划
  • 胆囊疾病
  • 骨关节炎
  • 睡眠呼吸暂停与呼吸问题
  • 一些癌症(子宫内膜癌、乳腺癌和结肠癌)
函数CalculateBMI(){ var英寸=12; var-ft; var bmi=数学书写(重量*703)/(英寸高)^2;
如果(bmi我发现一些可能导致您出现问题的因素。让我们从以下陈述开始:

var bmi= Math.write(weight*703)/(inch height)^2;
您没有定义体重或身高(您必须告诉它查看文本框或将其发送到函数,它不会自动知道您指的是文本框)

var weight = document.getElementById('weight').value;
身高和体重之间没有符号,这是一个语法错误,如果他们要在一起,你需要对他们做些什么(要知道这不是增加英寸,只是计算英寸)

var bmi=(体重*703)/(英寸*高度)^2

之后,您将使用if-else-这在Javascript中无效,您可能会说:

else if (19<bmi<=25)

else if(19您的javascript有几个系统性错误


例如,
1Sorry,但是代码中充满了错误。首先,请着手解决语法错误。谢谢。这真的很有帮助。它帮助我比以前更好地理解javascript,但不管结果如何,它说我非常肥胖
var results;
if (bmi<=19)
{
  results = "Underweight"
}

document.getElementById('results').value = results;
function CalculateBMI(){
    // To avoid erros due to hoisting define all
    // of your vars at the top of your function    
    var ft,
    bmi,
    heighti_e, // height in inches
    heightf_e, // height in feat
    weight_e,
    bmi_e,  // the bmi element
    bmi;                 
    // Use getElementById to get a reference for the
    // elements you will be using in your function
    heighti_e=document.getElementById("heighti");
    heightf_e=document.getElementById("heightf");
    weight_e=document.getElementById("weight");
    bmi_e=document.getElementById("bmi");
    // Not all of these parenthesis are necessary but it
    // helps to clear up the order of operation and avoid
    // silly mistakes in long equations that are not
    // broken up into several lines
    bmi= (weight_e* 0.45) / (((12*heightf_e)+heighti_e) * 0.025)^2;
    //  set bmi to a string value
    if(bmi<=19)
    {
    bmi="Underweight";
    }
    else if(bmi>19 && bmi<=25)
    {
    bmi="Desirable";
    } 
    else if(bmi>25 && bmi<=29)
    {
    bmi="Prone to health risks";
    }
    else if (bmi>29 && bmi<=40)
    {
    bmi="obese";
    }
    else(bmi>40)
    {
    bmi="Extremely Obese";
    }
    bmi_e.value=bmi; // bmi_a is the reference to the
                     // element in your form with the
                     // bmi id
    return false; // make sure you return false to prevent
                  // page reload
}
<form action="" name="bmi" onsubmit="return CalculateBMI()">
     <p> Weight:<p/></td>  <td><input type="text" id="weight" name="weight" size="25" />

  <p>Height:</p> <input type="text" id="heightf" name="textbox" size="25" /><td><p>Ft.</p><input type="text" id="heighti" name="textbox" size="25" /> <p>In.</p>

  <input type="submit" id="Calculate BMI" name="Calculate BMI" value="Calculate BMI" size="25" />
  According to the Panel on 
  Energy, Obesity, and Body Weigth Standards published by
  American Journal of Clinical Nurttrition, your category is:
  <input type="text" id="bmi" name="textbox" size="25" />
</form>