-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
40 lines (34 loc) · 1.08 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
const url = "https://api.covid19api.com/summary";
getApiData = (url) => {
fetch(url)
.then((res) => {
return res.json();
})
.then((data) => {
console.log(data);
let country = data.Countries[77].Country;
let totalCases = data.Countries[77].TotalConfirmed;
let totalDeaths = data.Countries[77].TotalDeaths;
let newCase = data.Countries[77].NewConfirmed;
let newDeaths = data.Countries[77].NewDeaths;
let today = new Date().toDateString();
displayData(
country,
totalCases,
totalDeaths,
newCase,
newDeaths,
today
);
})
.catch((error) => {
console.log(error);
});
}
function displayData(c, tc, td, nc, nd, t) {
let pre = document.createElement("pre");
console.log(tc);
pre.innerHTML = `<span>Country Name: </span> ${c}\n<span>Date: </span> ${t} \n<span>Total Cases: </span> ${tc} \n<span>Total Deaths: </span>${td} \n<span>New Cases: </span>${nc} \n<span>New Deaths: </span>${nd}`;
document.getElementById("myDiv").appendChild(pre);
}
getApiData(url);