-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
81 lines (58 loc) · 1.85 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
var url="https://api.covid19api.com/summary";
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var json=JSON.parse(this.responseText);
iter(json.Countries);
// console.log(json.Countries[0]);
}
};
xhttp.open("GET", url, true);
xhttp.send();
function print(x)
{
console.log(x);
}
function getExactdate(tempdate)
{
let months=["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"];
let date=tempdate.split("-");
let year=date[0];
let day=date[1];
let month=date[2];
month=(month.toString().startsWith("0"))?month.charAt(1):month;
let exactdate=months[month-1]+" "+day+", "+year;
return exactdate;
}
function draw(country)
{
let tempDate=country.Date.toString().split("T")[0];
let exactDate=getExactdate(tempDate);
let MONTHHOLDER=document.getElementById("MONTH");
MONTHHOLDER.innerHTML="As of "+exactDate;
let confirmed=document.getElementById("confirmed");
confirmed.innerHTML=country.TotalConfirmed;
let recovered=document.getElementById("recovered");
recovered.innerHTML=country.TotalRecovered;
let deaths=document.getElementById("deaths");
deaths.innerHTML=country.TotalDeaths;
let newconfirmed=document.getElementById("newconfirmed");
newconfirmed.innerHTML=country.NewConfirmed;
let newrecovered=document.getElementById("newrecovered");
newrecovered.innerHTML=country.NewRecovered;
let newdeaths=document.getElementById("newdeaths");
newdeaths.innerHTML=country.NewDeaths;
console.log(country);
}
function iter(arr)
{
for(var i=0;i<arr.length;i++)
{
let country=arr[i];
if(country.Country=="Philippines")
{
draw(country);
break;
}
}
}