-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (29 loc) · 1.02 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
async function getAdviceFromServer() {
let response = await fetch('https://api.adviceslip.com/advice', {cache: 'no-store'})
let data = await response.json();
return data;
}
function createAdwice(data) {
let textAdwice = document.querySelector(".textAdvice");
let labelAdwice = document.querySelector(".label");
labelAdwice.textContent = `ADVICE #${data.id}`;
textAdwice.textContent = `"${data.advice}"`;
}
let idAdvice = null;
function getAdviceClickHandler() {
buttonGetAdvice.disabled = true;
buttonGetAdvice.classList.add("spin");
getAdviceFromServer()
.then(data => {
createAdwice(data.slip)
buttonGetAdvice.classList.remove("spin");
buttonGetAdvice.disabled = false;
return data;
})
.catch(error=>console.log("error",error))
}
function loadFirstAdvice() {
getAdviceClickHandler();
}
buttonGetAdvice.addEventListener("click", getAdviceClickHandler);
document.addEventListener("DOMContentLoaded", loadFirstAdvice);