From 70850786eab1de38c71f5a56c72ed87fdbad0251 Mon Sep 17 00:00:00 2001 From: Deepak Kumar Date: Wed, 12 Oct 2022 00:34:03 +0530 Subject: [PATCH] added news Website --- Public/News_Website/index.html | 50 ++++++++++++++++++++++++++++++++++ Public/News_Website/main.js | 35 ++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Public/News_Website/index.html create mode 100644 Public/News_Website/main.js diff --git a/Public/News_Website/index.html b/Public/News_Website/index.html new file mode 100644 index 00000000..04fd5f1b --- /dev/null +++ b/Public/News_Website/index.html @@ -0,0 +1,50 @@ + + + + + + + + News from around the globe every day + + + + +
+

Latest News by: Daily News

+
+
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/Public/News_Website/main.js b/Public/News_Website/main.js new file mode 100644 index 00000000..f742c964 --- /dev/null +++ b/Public/News_Website/main.js @@ -0,0 +1,35 @@ +console.log("Hello World!"); + +let newsAccordian = document.getElementById('accordian'); +let country = 'in'; +let apiKey = 'b598648722f84619b927f4e38f64aed3'; + +const xhr = new XMLHttpRequest(); +xhr.open('GET', `https://newsapi.org/v2/top-headlines?country=${country}&apiKey=${apiKey}`, true); + +xhr.onload = function () { + let json = JSON.parse(this.responseText); + console.log(json); + let articles = json.articles; + let newsHtml = ""; + articles.forEach(function (element, index) { + let news = `

+ +

+
+
+
+ ${element['description']}Read more + +
+
+
+
+

`; + newsHtml += news; + }); + newsAccordian.innerHTML = newsHtml; + console.log(articles); +} + +xhr.send();