-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (27 loc) · 892 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
29
const adviceId=document.querySelector('.advice_id')
const advice=document.querySelector('.advice')
const dice=document.querySelector('.circle')
const leftDoubleQuote = '\u201C'; // “
const rightDoubleQuote = '\u201D'; // ”
const getAdvice=()=>{
function processData(data) {
// Process the data received from the API
console.log(data.slip)
adviceId.textContent=`#${data.slip.id}`
advice.textContent=`${leftDoubleQuote}${data.slip.advice}${rightDoubleQuote}`
}
// Send the GET request
fetch('https://api.adviceslip.com/advice')
.then(response => response.json())
.then(data => {
// Handle the JSON response
processData(data);
})
.catch(error => {
// Handle any errors
console.error('Error:', error);
})};
getAdvice()
const newAdvice=()=>{
getAdvice()
}