forked from codemistic/Web-Development
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
24 lines (20 loc) · 710 Bytes
/
script.js
File metadata and controls
24 lines (20 loc) · 710 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
const nextQuote = document.querySelector(".quote-next");
const quote = document.querySelector(".quote-high");
const author = document.querySelector(".quote-author");
const BASE_URL = `https://api.quotable.io`;
const fetchQuote = async (pathname) => {
fetch(`${BASE_URL}/${pathname}`)
.then((res) => res.json())
.then((data) => {
// console.log(data);
quote.textContent = data.content;
author.textContent = `_${data.author}`;
nextQuote.id = `${data._id}`;
});
};
nextQuote.addEventListener("click", () => {
fetchQuote(`random`);
});
window.addEventListener("load", () => {
fetchQuote(`random`);
});