-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
26 lines (23 loc) · 870 Bytes
/
app.js
File metadata and controls
26 lines (23 loc) · 870 Bytes
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
document.addEventListener("DOMContentLoaded", () => {
// DOM elements
const button = document.querySelector("#new-quote");
const quote = document.querySelector("#text");
const cite = document.querySelector("#author");
async function updateQuote() {
// Fetch a random quote from the Quotable API
const response = await fetch("https://api.quotable.io/random");
const data = await response.json();
if (response.ok) {
// Update DOM elements
quote.textContent = data.content;
cite.textContent = data.author;
} else {
quote.textContent = "An error occured";
console.log(data);
}
}
// Attach an event listener to the `button`
button.addEventListener("click", updateQuote);
//updateQuote once when page loads
updateQuote();
});