-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (30 loc) · 840 Bytes
/
Copy pathapp.js
File metadata and controls
39 lines (30 loc) · 840 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
27
28
29
30
31
32
33
34
35
36
37
38
39
let advice="https://api.adviceslip.com/advice";
let quote=document.querySelector(".quote");
let btn=document.querySelector(".btn");
let count = document.querySelector(".count");
let counter=function() {
let n=Math.floor(Math.random()*1000 +1);
count.textContent=`Certified Internet Nonsense#${n}`
}
async function getAdv() {
try{
let res=await fetch(advice);
let data= await res.json();
let finalQuote=data.slip.advice;
quote.textContent=`${finalQuote}`;
} catch (error) {
quote.textContent = "Internet says... try again."
}
counter();
}
async function handleClick() {
if (btn.disabled) return;
btn.disabled = true;
try {
await getAdv();
} catch (err) {
console.error(err);
}
btn.disabled = false;
}
btn.addEventListener("click",handleClick);