-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
201 lines (136 loc) · 5.99 KB
/
script.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Variables
let usersName = document.getElementById("usersName").value;
let age = parseInt(document.getElementById("age").value);
let weight = parseInt(document.getElementById("weight").value);
let userHeight = parseInt(document.getElementById("userHeight").value);
// Array
let myList = [{
name: (usersName),
age: (age),
height:(userHeight),
weight: (weight),
}];
//Add Name to Object:
let addName = document.getElementById('addName');
addName.addEventListener("click", function(){
let usersName = document.getElementById("usersName").value;
myList.push({name:usersName})
document.getElementById("object").append(` Name: ${myList[1].name} `);
myList.keys(usersName)
})
// Add Age to Object:
let addAge = document.getElementById('addAge');
addAge.addEventListener("click", function(){
let age = document.getElementById('age').value;
myList.push({age:age})
document.getElementById("storeAge").innerText = (` Age: ${myList[2].age} `);
})
// Add Height to Object:
let addHeight = document.getElementById("addHeight");
addHeight.addEventListener("click", function(){
let height = document.getElementById("userHeight").value;
myList.push({height:height})
document.getElementById("storeHeight").innerText = (` Height: ${myList[3].height} inches`);
})
//Add Weight to Object:
let addWeight = document.getElementById('addWeight');
addWeight.addEventListener("click", function(){
let weight = document.getElementById('weight').value;
myList.push({weight:weight})
document.getElementById("storeWeight").innerText = (` Weight: ${myList[4].weight} .lbs`);
})
// BMI
//--------------------------------------------------------------------------------------------------
//Variables
let bmiButton = document.getElementById("bmiButton");
bmiButton.addEventListener("click", function(){
let weight = document.getElementById("weight").value;
let userHeight = document.getElementById("userHeight").value;
//Calculation for BMI
let Bmi = Math.fround((weight * 703) / (userHeight * userHeight));
console.log(Bmi);
// If Conditional - Weight checks to see if you are over or underweight.
document.getElementById("bmi").append(Bmi);
})
// BODY Fat
let bodyFat = document.getElementById("bodyFat");
bodyFat.addEventListener("click", function(){
let bdyFat = document.getElementById("bdyFat").value;
let userAge = document.getElementById("age").value;
let weight = parseInt(document.getElementById("weight").value);
let userHeight = parseInt(document.getElementById("userHeight").value);
let sex = document.getElementById("sex").value;
let bmi = Math.fround((weight * 703) / (userHeight * userHeight));
if (sex === "female"){
let bdyFat1 = (1.20 * (bmi))
let bdyFat2 = (0.23 * (userAge))
let bdyFatTotal = Math.floor(bdyFat1 + bdyFat2 - 5.4);
document.getElementById("bdyFat").append(`${bdyFatTotal}% Body Fat`);
console.log(`${bdyFatTotal}% Body Fat`);
}else if (sex === "male"){
let bdyFat1 = (1.20 * (bmi))
let bdyFat2 = (0.23 * (userAge))
let bdyFatTotal2 = Math.floor(bdyFat1 + bdyFat2 - 16.2);
document.getElementById("bdyFat").append(`You are: ${bdyFatTotal2}% Body Fat`);
}else {
console.log("Program Failed...")
}
})
// Print Summary Section
printSum.addEventListener("click", function(){
let printSum = document.getElementById("printSum");
printSum.addEventListener("click", function(){
let userAge = document.getElementById("age").value;
let weight = parseInt(document.getElementById("weight").value);
let userHeight = parseInt(document.getElementById("userHeight").value);
let sex = document.getElementById("sex").value;
let bmi = Math.fround((weight * 703) / (userHeight * userHeight));
if (sex === "female"){
let printSum = document.getElementById("printSum");
let bdyFat1 = (1.20 * (bmi))
let bdyFat2 = (0.23 * (userAge))
let bdyFatTotal = Math.floor(bdyFat1 + bdyFat2 - 5.4);
bmiMessage()
document.getElementById("summary").append(`${bdyFatTotal}% Body Fat`);
console.log(`${bdyFatTotal}% Body Fat`);
}else if (sex === "male"){
let summary = document.getElementById("summary");
let bdyFat1 = (1.20 * (bmi))
let bdyFat2 = (0.23 * (userAge))
let bdyFatTotal3 = Math.floor(bdyFat1 + bdyFat2 - 16.2);
console.log(`${bdyFatTotal3}% Body Fat`)
bmiMessage()
summary.append(` - You are:${bdyFatTotal3}% Body Fat`);
}else {
console.log("Program Failed...")
}
function bmiMessage(){
if (bmi < 18.5){
document.getElementById("summary").append(`At ${weight} .lbs, Your BMI is ${bmi}, and you are underweight! `);
console.log("You are underWeight!");
}else if (bmi > 18.5 && bmi < 24.9){
document.getElementById("summary").append(`At ${weight} .lbs, Your BMI is ${bmi}, and you are at a normal weight!!`);
console.log(" You are Normal Weight");
}else if (bmi > 24.9 && bmi < 30){
document.getElementById("summary").append(`At ${weight} .lbs, Your BMI is ${bmi}, and you are overweight!!`);
console.log("You are OverWeight!!")
}else if (bmi > 31){
document.getElementById("summary").append(`At ${weight} .lbs, Your BMI is ${bmi}, and you are obese!!`);
console.log("You are Obese!!")
}else {
console.log("Didn't Work!")
}
}
})
})
// Picture Sizing
let bmiIndex = document.getElementById('bmiIndex');
bmiIndex.addEventListener("click", function(){
bmiIndex.id = 'bmiIndexEnlarged'
})
bmiIndex.addEventListener("dblclick", function(){
bmiIndex.id = 'bmiIndex'
})
// Object.keys(myList).forEach(function(property){
// console.log(myList[property]);
// });