diff --git a/fetch101/index.html b/fetch101/index.html new file mode 100644 index 0000000..83efc75 --- /dev/null +++ b/fetch101/index.html @@ -0,0 +1,23 @@ + + + + + News + + +

Newzies

+

My Article List

+ + + + + + diff --git a/fetch101/script.js b/fetch101/script.js new file mode 100644 index 0000000..11fd2a7 --- /dev/null +++ b/fetch101/script.js @@ -0,0 +1,56 @@ + +$('select').change(function(){ + + + var source = $('select option:selected').text() + var url = 'https://newsapi.org/v1/articles?source=' + source +'&apiKey=43e72e768c96496a9d0d20b68ce97391'; + $('ul').empty() + + + var apiCall = fetch(url) + console.log('api Call') + console.log(apiCall) + +apiCall +.then((response)=>{//when we get response back + console.log('response received') + // console.log(response.json()) + return response.json() +}) +.then(writeLiEveryArticle) +.catch((err)=>{ + console.log(err) +}) + +function writeLiEveryArticle(data){ + //loop the data.article + var articles = data.articles + var $ul =$('ul') + var $button = $(' +

+ + + + diff --git a/script.js b/script.js new file mode 100644 index 0000000..c08d1a5 --- /dev/null +++ b/script.js @@ -0,0 +1,31 @@ + + +$('button').on('click',function(){ + + var apiCall = fetch('https://andruxnet-random-famous-quotes.p.mashape.com/', { + method: "POST", + headers: {"X-Mashape-Key": 'tCaKCH3PLNmshllrY4Js9pw14VyXp12WHT1jsnO7Jq1NoEket8', + "Content-Type": 'application/x-www-form-urlencoded', + 'Accept': 'application/json'}, + }); + +apiCall +.then((response)=>{//when we get response back + console.log('response received') + // console.log(response.json()) + return response.json() +}) +.then(randomQuote) +.catch((err)=>{ + console.log(err) +}) + +function randomQuote(data){ + console.log(data) + + quote = data.quote + console.log(quote) + $('h2').text(quote) +} + +})