-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
209 lines (179 loc) · 5.62 KB
/
index.html
File metadata and controls
209 lines (179 loc) · 5.62 KB
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
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Mini App</title>
<style>
div.user-photo {
margin: 1em auto;
}
body{
background-color: white;
}
.select{
margin-bottom: 2.5em;
}
.user-photo{
width: 150px;
height: 150px;
border-radius : 50%;
overflow: hidden;
}
.details {
color: white;
background-color: #6200ee;
font-size: 1.3em;
margin-top: 4em;
padding: 0.5em 1em 0.5em 1em;
border-radius: 10px;
}
.details p{
margin: 0.3em;
}
#outcome{
position: absolute;
right: 2.2em;
bottom: 6.5em;
width: 100px;
text-align: center;
}
#outcome h3 {
padding: 1em;
background-color: white;
border-radius: 10%;
margin: 0;
}
#outcome p {
color: white;
border-bottom: 5px solid white;
font-size: 2em;
margin: 0;
padding: 0.5em 0em 0.5em 0em;
}
#oracle{
margin-top: 2.5em;
border: 1px solid;
width: 100%;
}
</style>
</head>
<body>
<button id="filter-query" class="mdc-icon-button material-icons" >
filter_list
</button>
<div class="select">
<select class="select-text">
<option disabled selected>Select User</option>
</select>
</div>
<div class="user-photo">
<img src="https://via.placeholder.com/150" alt="Placeholder Image" />
</div>
<div class="details mdc-elevation--z3">
<p>
<span class="prop" data-age>Age:</span>
<span class="value" data-age-value></span></p>
<p>
<span class="prop" data-height>Height:</span>
<span class="value" data-height-value></span>
</p>
<p>
<span class="prop" data-weight>Weight:</span>
<span class="value" data-weight-value></span>
</p>
<p>
<span class="prop" data-gender>Gender:</span>
<span class="value" data-gender-value></span>
</p>
<p>
<span class="prop" data-country>Country:</span>
<span class="value" data-country-value></span>
</p>
</div>
<button id="oracle" class="mdc-button">Calculate BMI</button>
<div id="outcome">
<h3 class="mdc-typography--headline5">BMI</h3>
<p></p>
</div>
<script>
const users = [];
const computeBMI = ({weight, height, country}) =>{
let bmi = weight/(Math.pow(height*0.3048, 2));
let healthyCountry = ['Chad', 'Sierra Leone', 'Mali', 'Gambia', 'Uganda', 'Ghana', 'Senegal', 'Somalia', 'Ivory Coast', 'Israel'];
if(healthyCountry.indexOf(country) != -1){
bmi = bmi*0.82;
}
return parseFloat(bmi).toPrecision(3);
};
const getSelectedUser = (userId) => users.find(({id}) => id == userId);
const displaySelectedUser = ({ target }) => {
let user = getSelectedUser(target.value);
let properties = Object.keys(user);
properties.forEach((key) => {
let domel = document.querySelector(`span[data-${key}-value]`);
if (domel) {
domel.textContent = user[key];
}
});
}
const displaySelectedUser = (event) => {
let { target } = event;
let user = getSelectedUser(target.value);
let properties = Object.keys(user);
properties.forEach((key) => {
let domel = document.querySelector(`span[data-${key}-value]`);
if (domel) {
domel.textContent = user[key];
}
});
}
const letsCalculateBMI = () => {
let element = document.querySelector(".select-text");
let userId = element.options[element.selectedIndex].value;
let user = getSelectedUser(userId);
let bmi = computeBMI(user);
let pdom = document.querySelector("#outcome p");
pdom.textContent = bmi;
}
const powerupTheUI = () => {
document.querySelector('.select-text').addEventListener('change', displaySelectedUser);
document.querySelector('#oracle').addEventListener('click',
letsCalculateBMI);
}
const displayUsers = (users) => {
let select = document.querySelector('.select-text');
users.forEach((user)=>{
var opt = document.createElement('option');
opt.appendChild( document.createTextNode(user.name) );
opt.value = user.id;
select.appendChild(opt);
});
}
const fetchAndDisplayUsers = () => {
users.push({
age: 40,
weight: 75,
height: 6,
gender: 'Male',
country: 'Nigeria',
name: 'Charles Odili',
id: 'dfhb454768DghtF'
},
displayUsers(users);
then((response) => response.json()).then(({results}) => {
let [user] = results;
users.push(user);
displayUsers([user]);
}).catch(error => console.error("API problem", error));
};
const startApp = () => {
powerupTheUI();
fetchAndDisplayUsers();
};
startApp();
</script>
</body>
</html>