2015-11-26 89 views
2

我使用美國海軍公式修改了身體脂肪計算器。 中的計算器提供 1. BMR 2.最小熱量需求 3.身體脂肪BMR計算器:在BMR計算器中用瘦體重代替體重

計算器工作良好,但我想的基礎代謝率到​​利用瘦體重,而不是重量(形式提供)

我在BMR計算之前增加了wt1 = wt-(wt/100 * fatPercent)。

控制檯顯示沒有錯誤,但我執行腳本時沒有得到任何結果。不知道如何糾正這一點。

在此先感謝

Javascript代碼

<script type="text/javascript"> 
<!-- 
function Calculate() 
{ 
     var ht = parseFloat(document.cal_frm.txtHeight.value); 
     var nk = parseFloat(document.cal_frm.txtNeck.value); 
     var wa = parseFloat(document.cal_frm.txtWaist.value); 
     var hp = parseFloat(document.cal_frm.txtHip.value); 
     var wt = parseFloat(document.cal_frm.txtWeight.value); 
     var ag = parseInt(document.cal_frm.txtAge.value); 
     var sexf=false; 
     if (document.cal_frm.opGender.value == "1"){sexf=true;} 
     if (document.cal_frm.opHeight.value == "1") {ht = ht * 2.54;} 
     if (document.cal_frm.opNeck.value == "1") {nk = nk * 2.54;} 
     if (document.cal_frm.opWaist.value == "1") {wa = wa * 2.54;} 
     if (document.cal_frm.opHip.value == "1") {hp = hp * 2.54;} 
     if (document.cal_frm.opWeight.value == "1") {wt = wt * 0.4536;} 
     document.getElementById('feedback').innerHTML=''; 
     var errors=''; 
     if ((ht < 122) || (ht > 230) || isNaN(ht)){ 
     err=((document.cal_frm.opHeight.value == "1")? '48inches to 90inches' : '122cm to 230cm'); 
errors+='Enter height between '+err+'!n';} 
     if ((nk < 10) || (nk > 100) || isNaN(nk)){ 
     err=((document.cal_frm.opNeck.value == "1")? '6inches to 20inches' : '15cm to 50cm'); 
errors+='Enter neck between '+err+'!n';} 
     if ((wa < 20) || (wa > 200) || isNaN(wa)){ 
     err=((document.cal_frm.opWaist.value == "1")? '20inches to 80inches' : '50cm to 150cm'); 
errors+='Enter waist between '+err+'!n';} 
     if ((wt < 30) || (wt > 150) || isNaN(wt)){ 
     err=((document.cal_frm.opWeight.value == "1")? '67lb to 333lb' : '30Kg to 150Kg'); 
errors+='Enter weight between '+err+'!n';} 
     if ((ag < 19) || (ag > 70) || isNaN(ag)){ 
     err='19yrs to 70yrs'; 
errors+='Enter age between '+err+'!n';} 
     if (sexf==true){ 
      if ((hp < 50) || (hp > 200) || isNaN(hp)){ 
      err=((document.cal_frm.opHip.value == "1")? '20inches to 100inches' : '50cm to 250cm'); 
errors+='Enter hip between '+err+'!n';}} 
     if(errors){ 
      alert('The following error(s) occurred:n'+errors); 
      return;} 
     var BMR; 
     var fatpercent; 
     if (sexf==true) { 
      fatPercent = 495/(1.29579 - 0.35004 * (logten(wa + hp - nk)) + 0.221 * (logten(ht))) - 450; 
      wt1 = wt-(wt/100*fatPercent) /*added below code to substitute weight with lean body mass in the below calculation*/ 
      BMR = 655 + (9.6 * wt1) + (1.8 * ht) - (4.7 * ag); 
     } 
     else{ 
      fatPercent = 495/(1.0324 - 0.19077 * (logten(wa - nk)) + 0.15456 * (logten(ht))) - 450; 
      wt1 = wt-(wt/100*fatPercent)/*added below code to substitute weight with lean body mass in the below calculation*/ 
      BMR = 66 + (13.7 * wt1) + (5 * ht) - (6.8 * ag); 
     } 
     BMR=Math.round(BMR*10)/10; 
     fatPercent = (Math.round(fatPercent*10))/10; 
     var dailyCal; 
     if (document.cal_frm.opActivity.value == "0") {dailyCal = BMR * 1.2;} 
     if (document.cal_frm.opActivity.value == "1") {dailyCal = BMR * 1.375;} 
     if (document.cal_frm.opActivity.value == "2") {dailyCal = BMR * 1.55;} 
     if (document.cal_frm.opActivity.value == "3") {dailyCal = BMR * 1.725;} 
     if (document.cal_frm.opActivity.value == "4") {dailyCal = BMR * 1.9;} 

if (document.cal_frm.opWeight.value == "1") { 

     document.getElementById('feedback').innerHTML = "<p>Your BMR is: " + BMR + "<br />" + "Minimum Calorie 

requirement is: " + (Math.round(dailyCal)) + ";<br />" + "Your Body Fat is " + fatPercent + "%." + ";<br /></p>"; 
} 
function logten(v){ 
    return (Math.log(v)/Math.log(10)); 
} 
function resetAll(){ 
document.getElementById('feedback').innerHTML =''; 
} 
} 
--> 
</script> 

HTML代碼

<form name="cal_frm" id="cal_frm" style="width:400px; margin:20px 10px 20px 10px;" onsubmit="return false"> 
<table style="width:400px; margin:0px 10px 20px 10px;"> 
<tr><td style="width: 275px;"> 
<table id="cal_data"> 
<tr> 
<td style="padding-left:5px;">Height:</td> 
<td><input class="cal_text" type="text" name="txtHeight" size="20" ></td> 
<td><select class="cal_option" name="opHeight"> 
<option value="0">Cm</option> 
<option value="1">Inch</option> 
</select></td> 
</tr> 
<tr> 
<td style="padding-left:5px;">Neck:</td> 
<td><input class="cal_text" type="text" name="txtNeck" size="20" ></td> 
<td><select class="cal_option" name="opNeck"> 
<option value="0">Cm</option> 
<option value="1">Inch</option> 
</select></td> 
</tr> 
<tr> 
<td style="padding-left:5px;">Waist:</td> 
<td><input class="cal_text" type="text" name="txtWaist" size="20" ></td> 
<td><select class="cal_option" name="opWaist"> 
<option value="0">Cm</option> 
<option value="1">Inch</option> 
</select></td> 
</tr> 
<tr> 
<td style="padding-left:5px;">Hip (Female):</td> 
<td><input class="cal_text" type="text" name="txtHip" size="20" ></td> 
<td><select class="cal_option" name="opHip"> 
<option value="0">Cm</option> 
<option value="1">Inch</option> 
</select></td> 
</tr> 
<tr> 
<td style="padding-left:5px;">Weight:</td> 
<td><input class="cal_text" type="text" name="txtWeight" size="20" ></td> 
<td><select class="cal_option" name="opWeight"> 
<option value="0">Kg</option> 
<option value="1">Pound</option> 
</select></td> 
</tr> 
</table> 
</td> 
<td style="padding: 10px 0 0 10px;"> 
Gender:<br > 
<select class="cal_option" style="width:72%;border: solid 1px silver;" name="opGender"> 
<option value="0">Male</option> 
<option value="1">Female</option> 
</select><br ><br > 
Age:<br > 
<input class="cal_text" style="width:60%;border: solid 1px silver;" type="text" name="txtAge" size="20" > yrs. 
</td> 
</tr> 
<tr> 
<td colspan="2" style="padding:10px 0 10px 0;"><span style="padding:0 2px;">Activity:</span> 
<select id="Select7" class="cal_option" style="width:80%; border:1px solid silver;" name="opActivity"> 
<option selected="selected" value="0">Sedentary (Very little or no exercise)</option> 
<option value="1">Lightly active (light exercise/sports 1-3 days/week)</option> 
<option value="2">Moderately active (moderate exercise/sports 3-5 days/week)</option> 
<option value="3">Very active (hard exercise/sports 6-7 days a week)</option> 
<option value="4">Extra active (very hard exercise/sports & physical job or 2x training)</option> 
</select> 
</td> 
</tr> 
<tr> 
<td id="feedback" colspan="2" style="padding:0 0 5px 0; font-family:arial; font-size:11px; color:#333333;" ><a 

style="font-size:1px;color:#ffffff;line-height:1%;" href="http://ramui.com">http://ramui.com</a></td> 
</tr> 
<tr> 
<td colspan="2"> 
<input onclick="Calculate()" class="cal_button" type="button" value="Calculate" >&nbsp;<input type="reset" 

class="cal_button" value="Reset" onclick="resetAll()" ></td> 
</tr></table> 
</form> 

回答

2

你輸出結果只有重量在磅規定。

+0

謝謝,我沒有意識到這一點。但是我仍然不明白這個問題。爲什麼其他人不工作?如果選擇kg,wt的值保持不變。如果選擇磅,wt轉換爲kgs。那麼可以做些什麼來糾正腳本的其餘部分? –

+0

if(document.cal_frm.opWeight.value ==「1」){/ *這是代碼,表示輸出* /} –

+0

感謝您的幫助。爲了向所有人澄清,我添加了第二個條件語句,其中的選項值爲0(公斤數)-------- if(document.cal_frm.opWeight.value ==「0」){document.getElementById('feedback')document.getElementById ).innerHTML =「

您的BMR是:」+ BMR +「
」+「最低卡路里 要求是:」+(Math.round(dailyCal))+「;
」+「您的身體脂肪是」+ fatPercent +「%」。 +「;

」; } ------ –