1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
const fetchBtn = document.querySelector('.fetch-button'); const quoteOutput = document.querySelector('.quote-output'); const quoteContainer = document.querySelector('.quote-container');
function getQuote() { fetch('https://ron-swanson-quotes.herokuapp.com/v2/quotes').then(function (response) { if (response.ok) { return response.json() } else { return Promise.reject(response); } }).then(function (data) { renderQuote(data) alterGradient() }).catch(function (err) { console.log(err); return err; }) }
function renderQuote(data) { quoteOutput.innerHTML = `<p class="quote-paragraph"> ${data[0]}</p>`; }
function alterGradient() { quoteContainer.style.background = `linear-gradient(${Math.floor(Math.random() * (90 - 35)) + 90}deg, rgba(142,69,${Math.floor(Math.random() * (255 - 100)) + 255},1), ${Math.floor(Math.random() * (20 - 10)) + 20}%, rgba(74,${Math.floor(Math.random() * (90 - 60)) + 90},${Math.floor(Math.random() * (280 - 140)) + 280},.8) ${Math.floor(Math.random() * (40 - 30)) + 40}%, rgba(142,69,255,1) 83%)` }
getQuote()
fetchBtn.addEventListener('click', getQuote);
|