diff --git a/created.txt b/created.txt new file mode 100644 index 0000000..3b18e51 --- /dev/null +++ b/created.txt @@ -0,0 +1 @@ +hello world diff --git a/index.html b/index.html new file mode 100644 index 0000000..48aa515 --- /dev/null +++ b/index.html @@ -0,0 +1,86 @@ + + + + Hello! + + + + + + + +
+
+ + +
+ +
+ +
+
+

+        
+
+ +

NEWS LIST

+
+

+ 1.Article +

+

+

+
+ + +
+

+ 2.Article +

+

+

+
+ + +
+

+ 3.Article +

+

+

+
+ + +
+

+ 4.Article +

+

+

+
+ + +
+

+ 5.Article +

+

+

+
+ + +

+ 6.Article +

+ + diff --git a/sample.txt b/sample.txt new file mode 100644 index 0000000..3b18e51 --- /dev/null +++ b/sample.txt @@ -0,0 +1 @@ +hello world diff --git a/script.js b/script.js new file mode 100644 index 0000000..4df271c --- /dev/null +++ b/script.js @@ -0,0 +1,63 @@ +let data; +function getData(url, method) { + return new Promise(function(resolve, reject) { + const xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState !== 4) return; + if (xhr.status >= 200 && xhr.status < 300) { + resolve(JSON.parse(xhr.response)); + let data = JSON.parse(this.response) + } else { + reject({ + status: xhr.status, + statusText: xhr.statusText + }); + } + } + + xhr.open(method, url); + xhr.send(); + }); +} + +const url = "https://newsapi.org/v2/everything?q=bitcoin&from=2019-10-13&sortBy=publishedAt&apiKey=0c5aa5107409412a82f137ff8148d6eb" + +getData(url, 'GET').then(function(value) { + console.log('True API', value); + data = value; + for(let i=0; i<5; i++){ + document.getElementsByClassName("art")[i].innerHTML += data.articles[i].author; + document.getElementsByClassName("art")[i].innerHTML += data.articles[i].title; + document.getElementsByClassName("art")[i].innerHTML += data.articles[i].description; + } + +}).catch(function(error) { + console.log('ERROR IS', error); +}) + +let favNews = []; + const addUsername = (ev)=>{ + ev.preventDefault(); //to stop the form submitting + let user = { + username: document.getElementById('userInput').value, + } + //document.write("Hello" + user + "!" + "Welcome to News List.") + favNews.push(user); + document.forms[0].reset(); // to clear the form for the next entries + + console.warn('added' , {favNews} ); + let pre = document.querySelector('#msg pre'); + pre.textContent = '\n' + JSON.stringify(favNews, '\t', 2); + //saving to localStorage + localStorage.setItem('UserLogin', JSON.stringify(favNews) ); + } + document.addEventListener('DOMContentLoaded', ()=>{ + document.getElementById('btn').addEventListener('click', addUsername); + }); + +function addBookmark(){ + var element = document.getElementsByClassName("newsArticle"); + element.classList.add("addedBookmark"); +} + +addBookmark(); \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..ed3d464 --- /dev/null +++ b/style.css @@ -0,0 +1,24 @@ +/* CSS files add styling rules to your content */ + +body { + font-family: helvetica, arial, sans-serif; + margin: 2em; + } + + h1 { + font-style: italic; + color: #373fff; + } + + .bookmark{ + float: right; + } + + .addedBookmark { + width: 100%; + padding: 25px; + background-color: coral; + color: white; + font-size: 20px; + } + \ No newline at end of file