-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmr.js
77 lines (59 loc) · 2.2 KB
/
bmr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var age = document.querySelector('input[name="age"]').value;
var height = document.querySelector('input[name="height"]').value;
var weight = document.querySelector('input[name="weight"]').value;
var activityLevel = document.querySelector('select[name="level"]').value;
var calculate = document.querySelector('#calculate');
var reset = document.querySelector('#reset');
var daily = document.querySelector('#daily');
var gender = document.querySelector('select[name="gender"]').value;
document.querySelector('select[name="gender');
function bmrWomen(w,h,a){
var bmr = 665 + (4.35*w)+(4.7*h)-(4.7*a);
return bmr;
}
function bmrMen(w,h,a){
var bmr = 66 + (6.23*w)+(12.7*h) - (6.8*a);
return bmr;
}
function calories(bmr,level){
if (level==0){
return bmr*1.375;
}
else if (level==1){
return bmr*1.55;
}
else if (level==2){
return bmr*1.725;
}
else if (level==3){
return bmr*1.9;
}
}
calculate.addEventListener("click", function(){
age = document.querySelector('input[name="age"]').value;
height = document.querySelector('input[name="height"]').value;
weight = document.querySelector('input[name="weight"]').value;
activityLevel = document.querySelector('select[name="level"]').value;
console.log
gender = document.querySelector('select[name="gender"]').value;
console.log(gender);
if (gender==0){
var bmr = Math.round(bmrMen(weight,height,age));
var activity = Math.round(calories(bmr,activityLevel));
daily.textContent = "You must consume " + activity + " calories to maintain your current weight"
}
else if (gender==1){
var bmr = Math.round(bmrWomen(weight,height,age));
var activity = Math.round(calories(bmr,activityLevel));
daily.textContent = "Your BMI is " + bmr + " and you must consume " + activity + " calories to maintain your current weight"
}
}
);
reset.addEventListener("click", function(){
age = document.querySelector('input[name="age"]').value="";
height = document.querySelector('input[name="height"]').value="";
weight = document.querySelector('input[name="weight"]').value="";
activityLevel = document.querySelector('select[name="level"]').selectedIndex=0;
gender = document.querySelector('select[name="gender"]').selectedIndex = 0; //1 = option 2
daily.textContent = "";
});