forked from bellaxing/cs445-lab-solns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (44 loc) · 1.65 KB
/
index.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
const { from } = rxjs;
const { map, filter } = rxjs.operators;
window.onload = function() {
document.getElementById('emp-list-btn').onclick = function() {
fetchEmployees(document.getElementById('nums-emps').value);
}
}
async function fetchEmployees(numberOfEmps) {
let result = await fetch('https://randomuser.me/api/?results=' + numberOfEmps);
let emps = await result.json();
renderEmployees(emps.results);
}
function renderEmployees(emps) {
const empDiv = document.getElementById('employees');
empDiv.innerHTML = '';
from(emps)
.pipe(
filter(emp => emp.gender === 'female'),
map(emp => {
emp.myname = emp.name.first + " " + emp.name.last;
emp.mylocation = {};
emp.mylocation.firstline = emp.location.street.number + ' ' + emp.location.street.name;
emp.mylocation.secondline = emp.location.city + ' ' + emp.location.state + ' ' + emp.location.country + ' ' + emp.location.postcode;
return emp;
})
)
.subscribe(emp => {
let template = `
<div class="col">
${emp.myname}
</div>
<div class="col">
<p class="fw-bold">Location</p>
<p>${emp.mylocation.firstline} </p>
<p>${emp.mylocation.secondline}</p>
</div>
<hr>
`
let div = document.createElement('div'); //<div></div>
div.innerHTML = template; //<div>template</div>
div.classList = 'row'; //<div class="row">template</div>
empDiv.appendChild(div);
});
}