-
Notifications
You must be signed in to change notification settings - Fork 2
/
indexx.js
74 lines (60 loc) · 2.84 KB
/
indexx.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
let covidActive = document.getElementById('covidActive');
let covidRecovered = document.getElementById('covidRecovered');
let covidDeath = document.getElementById('covidDeath');
let load1 = false;
let load2 = false;
let fetchData = fetch('https://coronavirus-19-api.herokuapp.com/all');
fetchData.then(res => res.json()).then(data => {
console.log(data);
covidActive.innerHTML = data.cases;
covidDeath.innerHTML = data.deaths;
covidRecovered.innerHTML = data.recovered;
})
let covidcountryActive = document.getElementById('covidcountryActive');
let covidcountryRecovered = document.getElementById('covidcountryRecovered');
let covidcountryDeath = document.getElementById('covidcountryDeath');
let covidcountryCases = document.getElementById('covidcountryCases');
let fetchcoundata = (countryName)=>{
let fetchcountryData = fetch(`https://coronavirus-19-api.herokuapp.com/countries/${countryName}`);
fetchcountryData.then(res => res.json()).then(data => {
console.log(data);
covidcountryActive.innerHTML = data.active;
covidcountryDeath.innerHTML = data.deaths;
covidcountryRecovered.innerHTML = data.recovered;
covidcountryCases.innerHTML = data.cases;
})
}
let countryName = 'india';
fetchcoundata(countryName);
let btnSubmit = document.getElementById('countrySearch').addEventListener("click" , (e)=>{
e.preventDefault();
countryName = document.getElementById('inputCountry').value;
console.log(countryName);
fetchcoundata(countryName);
});
//news
let newsHtml= "";
let fetchnews = fetch('https://saurav.tech/NewsAPI/top-headlines/category/health/in.json')
.then(res=> res.json()).then(data =>{
console.log(data);
data.articles.forEach((element,index) =>{
let newss = `<div class="card mb-3">
<div class="row g-0" style="margin-top: 10px;">
<div class="col-md-4">
<img src="${element.urlToImage}" class="img-fluid rounded-start" alt="...">
</div>
<div class="col-md-8">
<div class="card-body">
<h3 class="card-title" id="newsHead">${element.title}</h3>
<p class="card-text">${element.description}</p>
<a href="${element.url}" class="card-link btn btn-primary">Know More...</a>
</div>
</div>
</div>
</div>`
newsHtml += newss;
console.log(newsHtml)
});
let neww = document.getElementById('news');
neww.innerHTML = newsHtml;
})