+ 1
Here the following API includes quotes. How to generate random quote here? I'm just able to generate an index.
4 ответов
+ 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"
}
]
+ 2
Calviղ Thanks 😀
+ 1
document.getElementById("set").innerHTML = data[foo].text;
0
Josh Greig Got it!
Thanks a lot😊