jsquotes/public/js/app.js

34 lines
845 B
JavaScript
Raw Normal View History

'use strict';
// Full year for footer
const todayDate = new Date();
jsyear.innerText = todayDate.getFullYear();
const quoteDisplay = document.querySelector(".quote");
let numQuotes;
let randomNum;
let intervalID;
let iteratorID = 0;
let currQuote;
2022-05-18 00:14:26 -05:00
2023-04-09 18:17:51 -05:00
fetch("https://cdn.fyrfli.link/FavouriteQuotes.json")
2022-05-18 00:14:26 -05:00
.then((response) => {
return response.json();
})
.then((data) => {
currQuote = getQuote(data);
for (let i = 0; i < 50; i++) {
quoteDisplay.innerText = currQuote;
intervalID = setInterval(() => {
currQuote = getQuote(data);
quoteDisplay.innerText = currQuote;
}, 12000);
}
});
function getQuote(data) {
let noQuotes = Object.entries(data).length;
let randNo = Math.floor(Math.random() * noQuotes);
return data[randNo].quote + "\n\n" + data[randNo].author.replace(/"/g, '');
2023-01-22 09:37:03 -06:00
}