-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
83 lines (68 loc) · 3.68 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
/* Global Data */
const url = "https://covid-api.mmediagroup.fr/v1/cases?country=Global";
fetch(url)
.then(function(response) {
return response.json();
}).then(function(json) {
console.log(json);
let results = "";
results += '<h1>Worldwide Statistics' + "</h1>";
results+= '<h5> Total cases: ' + json.All.confirmed + '</h5>';
// results+= '<h5> Total recovered: ' + json.All.recovered + '</h5>'; API Only returns 0
results+= '<h5> Total deaths: ' + json.All.deaths + '</h5>';
results+= '<h5> Up to date as of: ' + moment(json.All.updated).format('MMMM Do, YYYY hh:mm a') + '</h5>';
console.log(results);
document.getElementById("world-info").innerHTML = results;
});
/* Country Data */
document.getElementById("covidSubmit").addEventListener("click", function(event) {
event.preventDefault();
const value = document.getElementById("covidInput").value;
if (value === "")
return;
const url = "https://covid-api.mmediagroup.fr/v1/cases?country=" + value;
fetch(url)
.then(function(response) {
return response.json();
}).then(function(json) {
console.log(json);
let results = "";
results += '<hr>';
results += '<br> <h1>Covid-19 in ' + json.All.country + "</h1>";
results += '<h5> Confirmed Cases: ' + json.All.confirmed + '</h5>';
// results += '<h5> Total Recovered: ' + json.All.recovered + '</h5>'; API Only returns 0
results += '<h5> Confirmed Deaths: ' + json.All.deaths + '</h5>';
let perCapita = (json.All.confirmed / json.All.population) * 100000;
results += '<h5> Cases per 100,000 people: ' + perCapita + '</h5>';
results += "</span>";
console.log(results);
document.getElementById("countryResults").innerHTML = results;
});
//historical data
const url2 = "https://covid-api.mmediagroup.fr/v1/history?country=" + value + "&status=confirmed";
fetch(url2)
.then(function(response) {
return response.json();
})
.then(function(json) {
console.log(json);
let result = "";
result += '<br> <h2> Total Cases by Date: </h2>';
let index = 0;
let date = "2020-11-01";
console.log(json.All.country);
result += '<hr><h5>Date: Nov. 1, 2020 \t Cases: ' + json.All.dates["2020-11-01"] + '</h5>';
result += '<hr><h5>Date: Dec. 1, 2020 \t Cases: ' + json.All.dates["2020-12-01"] + '</h5>';
result += '<hr><h5>Date: Jan. 1, 2021 \t Cases: ' + json.All.dates["2021-01-01"] + '</h5>';
result += '<hr><h5>Date: Feb. 1, 2021 \t Cases: ' + json.All.dates["2021-02-01"] + '</h5>';
result += '<hr><h5>Date: Mar. 1, 2021 \t Cases: ' + json.All.dates["2021-03-01"] + '</h5>';
result += '<hr><h5>Date: Apr. 1, 2021 \t Cases: ' + json.All.dates["2021-04-01"] + '</h5>';
result += '<hr><h5>Date: May. 1, 2021 \t Cases: ' + json.All.dates["2021-05-01"] + '</h5>';
result += '<hr><h5>Date: June. 1, 2021 \t Cases: ' + json.All.dates["2021-06-01"] + '</h5>';
result += '<hr><h5>Date: July. 1, 2021 \t Cases: ' + json.All.dates["2021-07-01"] + '</h5>';
result += '<hr><h5>Date: Aug. 1, 2021 \t Cases: ' + json.All.dates["2021-08-01"] + '</h5>';
result += '<hr><h5>Date: Sep. 1, 2021 \t Cases: ' + json.All.dates["2021-09-01"] + '</h5>';
result += '<hr><h5>Date: Oct. 1, 2021 \t Cases: ' + json.All.dates["2021-10-01"] + '</h5></pre><hr>';
document.getElementById("Historical-Data").innerHTML = result;
});
});