forked from Avdhesh-Varshney/blog-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
29 lines (23 loc) · 1 KB
/
script.js
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
async function generateQuote() {
const quoteContainer = document.getElementById('quote');
const quoteContainerDiv = document.getElementById('quote-container');
// Hide the container while fetching the new quote
quoteContainerDiv.classList.remove('show');
quoteContainer.innerHTML = 'Loading...';
try {
const response = await fetch('https://api.quotable.io/random');
const data = await response.json();
quoteContainer.innerHTML = `"${data.content}" - ${data.author}`;
// Ensure a slight delay to allow CSS changes to apply
setTimeout(() => {
quoteContainerDiv.style.display = 'block';
quoteContainerDiv.classList.add('show');
}, 100);
} catch (error) {
quoteContainer.innerHTML = 'Error fetching quote. Please try again.';
setTimeout(() => {
quoteContainerDiv.style.display = 'block';
quoteContainerDiv.classList.add('show');
}, 100);
}
}