-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
146 lines (111 loc) · 4.14 KB
/
app.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//const QueryCountry = document.getElementById("inputQ").value;
//const QueryCountry = window.prompt(document.getElementById("inputQ").value);
//console.log(QueryCountry);
//Global Data
var totalCases = document.querySelector('.ispan-1');
var totalDea = document.querySelector('.ispan-2');
var totalRecovered = document.querySelector('.ispan-3');
//Country Data
var totalCountryCases = document.querySelector('.Cspan-1');
var totalCountryDea = document.querySelector('.Cspan-2');
var totalCountryRecovered = document.querySelector('.Cspan-3');
//insta-redirect
$(".fa-instagram").click(function(){
window.location.href ="https://www.instagram.com/_______the_wrong_guy__________/";
});
//on-keypress
$('.search-input').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
DataFetchCovid();
}
event.stopPropagation();
});
function DataFetchCovid() {
const QueryCountry = document.getElementById("inputQ").value;
var QueryAPIready = QueryCountry[0].toUpperCase() + QueryCountry.slice(1).toLowerCase();
var a = QueryAPIready;
console.log(a);
var amer = "Us";
if(a == amer)
{
a = "US";
var changeCountry = document.getElementById("couName");
let url ='https://pomber.github.io/covid19/timeseries.json'
changeCountry.innerHTML = a;
fetch(url)
.then(res => res.json())
.then(data => {
// string.match(/^abc$/)
const toFind = data[a];
const lengthOfTheArray = toFind.length - 1;
const Trecovered = toFind[lengthOfTheArray].recovered;
const Tdea = toFind[lengthOfTheArray].deaths;
const Tconfirmed = toFind[lengthOfTheArray].confirmed;
//passing the data
totalCountryCases.innerHTML = Tconfirmed;
totalCountryDea.innerHTML = Tdea;
totalCountryRecovered.innerHTML =Trecovered;
// console.log(Trecovered);
// console.log(Tdea);
// console.log(Tconfirmed);
})
.catch((err) =>{
alert("Yo enter a valid country");
})
}
else{
var changeCountry = document.getElementById("couName");
changeCountry.innerHTML = a;
let url ='https://pomber.github.io/covid19/timeseries.json'
fetch(url)
.then(res => res.json())
.then(data => {
// const toFind = data.match.regex;
const toFind = data[a];
const lengthOfTheArray = toFind.length - 1;
const Trecovered = toFind[lengthOfTheArray].recovered;
const Tdea = toFind[lengthOfTheArray].deaths;
const Tconfirmed = toFind[lengthOfTheArray].confirmed;
//passing the data
totalCountryCases.innerHTML = Tconfirmed;
totalCountryDea.innerHTML = Tdea;
totalCountryRecovered.innerHTML =Trecovered;
// console.log(Trecovered);
// console.log(Tdea);
// console.log(Tconfirmed);
})
.catch((err) =>{
totalCountryCases.innerHTML = '';
totalCountryDea.innerHTML = '';
totalCountryRecovered.innerHTML ='';
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Invalid country name! or data not present!',
heightAuto : true,
width: 300,
padding: '.5rem',
background: '#fff',
})
})
}
}
function worldData() {
fetch("https://covid19.mathdro.id/api")
.then(res => res.json())
.then(global => {
const Tcases = global.confirmed.value;
const Tdea = global.deaths.value;
const Trecovered = global.recovered.value;
console.log(Tcases);
console.log(Tdea);
console.log(Trecovered);
//passing the data to html
totalCases.innerHTML = Tcases;
totalDea.innerHTML = Tdea;
totalRecovered.innerHTML = Trecovered;
})
.catch(err => console.log(err))
}
worldData();