-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentertainment.js
49 lines (42 loc) · 1.45 KB
/
entertainment.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
console.log("everything is fine");
//95854c9a385442aba78d3202773d7adb (api)
let news = document.getElementById('news');
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://newsapi.org/v2/top-headlines?country=in&category=entertainment&apiKey=95854c9a385442aba78d3202773d7adb', true);
xhr.onload = function () {
if (this.status === 200) {
let json = JSON.parse(this.responseText);
let articles = json.articles;
//console.log(articles);
let newsHtml='';
articles.forEach(function(element,index){
let somenews = `
<div class="news-detail">
<div class="news-card-heading">
<h2><span class="breaking-news">Breaking News ${
index + 1
}:</span> ${element.title} </h2> </div>
<div class="news-card-image">
<img src=' ${
element.urlToImage
}' style="height: 200px; width:300px">
</div>
<br><br>
<p>${element.content}</p>
<br>
<br>
<button class="card-button">
<a href="${
element.url
}" target="_blank">Read more...</a>
</button>
</div>
<br>`;
newsHtml = newsHtml + somenews;
});
news.innerHTML = newsHtml;
} else {
console.log("some error occured!");
}
}
xhr.send();