Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

random generating api for quotes

const link = "https://type.fit/api/quotes";

diceBtn.addEventListener("click",fetchQuote);//changes quote by click

function fetchQuote(){
      fetch(link)
      .then(response => response.json())
      .then(data => {
        const randomQuoteIndex = Math.round(Math.random()*data.length);
        quote.innerHTML = data[randomQuoteIndex].text;
        (data[randomQuoteIndex]);
      });
}
fetchQuote();//starts page with quote immediatly
 
PREVIOUS NEXT
Tagged: #random #generating #api #quotes
ADD COMMENT
Topic
Name
1+7 =