-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
33 lines (26 loc) · 857 Bytes
/
app.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
30
31
32
33
// Ted Lasso API from https://tedlassoquotes.com
const url = "https://tedlassoquotes.com/v1/quote";
const btn = document.querySelector(".btn");
const result = document.querySelector(".result");
const author = document.querySelector(".author");
const img = document.querySelector(".author-img");
btn.addEventListener("click", () => {
fetchTedLassoQuote();
});
const fetchTedLassoQuote = async () => {
result.textContent = "Loading ...";
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error("there was an error");
}
const data = await response.json();
// console.log(data);
result.textContent = data.quote;
author.textContent = data.author;
img.src = data.profile_img;
} catch (error) {
result.textContent = "There was an error loading the quote.";
}
};
fetchTedLassoQuote();