Why it is not working. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

Why it is not working.

I want to display news using news api. async function getNews() { let linkData = await fetch('https://newsapi.org/v2/everything?q=tesla&from=2021-07-18&sortBy=publishedAt&apiKey=e5f31f2b67f5447db48731d6b9bae9aa'); let data = await linkData.json(); for (let i of data.articles) { console.log(i.description); } } getNews();

19th Aug 2021, 8:26 AM
Aditya Dhiman
Aditya Dhiman - avatar
3 Answers
+ 4
Have you tried it in different complier. Bcz some api Or modules don't work in sololearn
19th Aug 2021, 8:45 AM
Aysha
Aysha - avatar
+ 3
If you console log the data , it clearly says requests from browser not allowed except localhost
19th Aug 2021, 8:44 AM
Abhay
Abhay - avatar
0
If your code is in js window it won’t work. I think sololearns blocks it. But it works if you use js inside html I had written somthing similar using fetch. You have made some mistakes in fetch function. https://code.sololearn.com/WelfVZv2STg4/?ref=app
19th Aug 2021, 2:18 PM
Iftekhar Ahmed Pranto
Iftekhar Ahmed Pranto - avatar