日期:2014-05-16 浏览次数:20403 次
var age ;
var gender ;
var hFt ;
var hIn ;
var hT;
var weight;
var bmi;
var bmr;
var act;
var need;
var lose;
var gain;
function result(){
var name = document.getElementById('name');
age = document.getElementById('age');
gender = getGender();
hFt = document.getElementById('hFt');
hIn = document.getElementById('hIn');
hT= ((hFt*12) + hIn)*0.254;
weight = document.getElementById('weight');
bmi = getBmi();
bmr = getBmr();
act = document.getElementById('act').value;
need = getNeed();
lose = getLose();
gain = getGain();
alert("Name:"+name.value+"\n"+
"Age:"+age.value+"\n"+
"Height:"+hFt.value+"'"+hIn.value+"\n"+
"Weight:"+weight.value+"lbs"+"\n"+
"BMI:"+bmi.value+"\n"+
"BMR:"+bmr.value+"\n"+
"Activity level:"+act+"\n"+
"Caloric Need:"+need+"\n"+
"Caloric Need to lose 1/2 pound(s):"+lose+"/"+need+"\n"+
"Caloric Need to gain 1/2 pound(s):"+gain+"/"+need+"\n" );
}
function getBmi(){
return parseFloat((0.45359237*weight)/(hT*hT));
}
function getGender(){
var obj;
obj=document.getElementsByName('sex');
if(obj!=null){
var i;
for(i=0;i<obj.length;i++){
if(obj[i].checked){
return obj[i].value;
break;
}
}
}else{
return null;
}
}
function getBmr(){
var tBmr;
if(gender.value == "male"){
tBmr = 66 + (13.7 * weight * 0.45359237) + (5 * hT * 100) - (6.8*age);
}else{
tBmr = 665 + (9.6 * weight * 0.45359237) + (1.8 * hT* 100) - (4.7 * age);
}
return tBmr;
}
function getNeed(){
var tNeed;
if(act == 'Extremely Inactive'){
tNeed = bmr.value;
} else if(act == 'Sedentary'){
tNeed = bmr.value * 1.2;
}else if(act == 'Lightly Active'){
tNeed = bmr.value * 1.375;
} else if(act == 'Moderately Active'){
tNeed = bmr.value * 1.55;
} else if(act == 'Vigorously Active'){
tNeed = bmr.value * 1.725;
} else if(act == 'Extremely Active'){
tNeed = bmr.value * 1.9;
}
return tNeed;
}
function getLose(){
return (need - 3500);
}
function getGain(){
return (need + 3500);
}