jsquotes/app.js

33 lines
820 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
fetch("FavouriteQuotes.json")
.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, '');
}