+ 1

Here the following API includes quotes. How to generate random quote here? I'm just able to generate an index.

https://code.sololearn.com/W81RBgz2bGU3/?ref=app

29th Jul 2020, 3:00 PM
Shweta Mahajan
Shweta Mahajan - avatar
4 Answers
+ 2
This will work: fetch("https://type.fit/api/quotes").then(response=>response.json()).then(data=>{ var randomIndex = Math.floor(Math.random()*data.length); document.getElementById("set").innerHTML = data[randomIndex].text; }); The returned data also includes the author for each quote. Here is a snippet from the API response to help you understand the data structure: [ { "text": "Genius is one percent inspiration and ninety-nine percent perspiration.", "author": "Thomas Edison" }, { "text": "You can observe a lot just by watching.", "author": "Yogi Berra" }, { "text": "A house divided against itself cannot stand.", "author": "Abraham Lincoln" } ]
29th Jul 2020, 3:09 PM
Josh Greig
Josh Greig - avatar
+ 2
Calviղ Thanks 😀
29th Jul 2020, 3:09 PM
Shweta Mahajan
Shweta Mahajan - avatar
+ 1
document.getElementById("set").innerHTML = data[foo].text;
29th Jul 2020, 3:07 PM
CalviŐ˛
CalviŐ˛ - avatar
0
Josh Greig Got it! Thanks a lot😊
29th Jul 2020, 3:11 PM
Shweta Mahajan
Shweta Mahajan - avatar