-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (25 loc) · 876 Bytes
/
index.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
const btn = document.querySelector(".card__button");
let number = document.querySelector(".card__title__number");
let quote = document.querySelector(".card__advice__quote");
const url = "https://api.adviceslip.com/advice";
const defaultURL = "https://api.adviceslip.com/advice/71";
function newQuote() {
fetch(url)
.then(response => response.json())
.then(data => {
number.innerHTML = data.slip.id;
quote.innerHTML = data.slip.advice;
})
.catch(error => console.log(error));
}
function defaultQuote() {
fetch(defaultURL)
.then(response => response.json())
.then(data => {
number.innerHTML = data.slip.id;
quote.innerHTML = data.slip.advice;
})
.catch(error => console.log(error));
}
window.onload = defaultQuote;
btn.addEventListener("click", newQuote);