-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
63 lines (51 loc) · 2.56 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
fetch("https://disease.sh/v3/covid-19/all")
.then(res => res.json())
.then(data => {
document.getElementById("world-total-cases").innerHTML = data.cases.toLocaleString();
document.getElementById("world-tests").innerHTML = data.tests.toLocaleString();
document.getElementById("world-active-cases").innerHTML = data.active.toLocaleString();
document.getElementById("world-deaths").innerHTML = data.deaths.toLocaleString();
})
fetch("https://disease.sh/v3/covid-19/countries/United%20States")
.then(res => res.json())
.then(data => {
document.getElementById("us-total-cases").innerHTML = data.cases.toLocaleString();
document.getElementById("us-tests").innerHTML = data.tests.toLocaleString();
document.getElementById("us-active-cases").innerHTML = data.active.toLocaleString();
document.getElementById("us-deaths").innerHTML = data.deaths.toLocaleString();
})
fetch("https://disease.sh/v3/covid-19/countries")
.then(res => res.json())
.then(data => {
let countryList = [];
for (let i = 0; i < data.length; i++) {
countryList.push(data[i].country);
}
let dropBox = document.getElementById("country-dropdown");
for (let i = 0; i < countryList.length; i++) {
dropBox.options.add(new Option(countryList[i]));
}
})
let dropBox = document.getElementById("country-dropdown");
function updateStats() {
let dropVal = dropBox.options[dropBox.selectedIndex].text;
console.log(dropVal);
fetch("https://disease.sh/v3/covid-19/countries/"+dropVal)
.then(res => res.json())
.then(data => {
document.getElementById("other-total-cases").innerHTML = data.cases.toLocaleString();
document.getElementById("other-tests").innerHTML = data.tests.toLocaleString();
document.getElementById("other-active-cases").innerHTML = data.active.toLocaleString();
document.getElementById("other-deaths").innerHTML = data.deaths.toLocaleString();
})
}
function defaultStats() {
fetch("https://disease.sh/v3/covid-19/countries/Afghanistan")
.then(res => res.json())
.then(data => {
document.getElementById("other-total-cases").innerHTML = data.cases.toLocaleString();
document.getElementById("other-tests").innerHTML = data.tests.toLocaleString();
document.getElementById("other-active-cases").innerHTML = data.active.toLocaleString();
document.getElementById("other-deaths").innerHTML = data.deaths.toLocaleString();
})
}