-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
69 lines (59 loc) · 1.75 KB
/
main.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
/* start script */
$(()=>{
$('.alert').hide();
form=$('form').submit(ev=>{
ev.preventDefult();
});
$('.card').hide();
// for button action
$('.loader').hide();
if(localStorage.getItem('query')){
localStorage.getItem('query');
$('.saved').text(`Your recent search was ${localStorage.getItem('query')}`);
}
$('.btn-warning').click(e=>{
$('.loader').fadeIn();
search=$('.form-control').val();
//set storage item
localStorage.setItem('query',search);
console.log(localStorage)
if(search !==''){
setTimeout(()=>{
$('.loader').hide()
$('.form-control').val('');
console.log(search)
url=` https://coronavirus-19-api.herokuapp.com/countries/`;
endpoint=`${url}${search}`;
console.log(endpoint);
fetch(endpoint)
.then(info=> info.json())
.then( res=>{
console.log(res);
$('.card').fadeIn(2000)
$('.country').text(`country : ${res.country}`);
//anoda call
$('.cases').text(`cases : ${res.cases}`);
$('.today').text(`Today Cases : ${res.todayCases}`)
$('.recovered').text(` Recovered : ${res.recovered }`);
$('.deaths').text(`Deaths : ${res.deaths}`);
$('.todayDeaths').text(`Today's Death : ${res.todayDeaths}`);
$('.total').text(`Total Test ${res.totalTests}`);
$('.alert').hide();
}).catch(err=>{
//now shshow error elemen
$('.alert').fadeIn(1000);
$('#msg').text(`oops something when wrong `)
$('.card').fadeOut();
});
},3000);
}else {
location.reload();
$('.card').html(`cant find result for empty value`);
}
});
//click function to camcel alert
$('.cancel').click(()=>{
$('.alert').fadeOut(1000);
$('.card').show();
});
});