-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
29 lines (23 loc) · 876 Bytes
/
script.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 API_LINK = "https://api.adviceslip.com/advice";
const adviceNumber = document.querySelector('.advice-generator_advice-number')
const adviceQuote = document.querySelector('.advice-generator_quotes')
const fetchBtn = document.querySelector('button.advice-generator_btn')
const fetchNewAdvice = async () => {
const response = await fetch(API_LINK);
const advice = await response.json()
return advice
};
const ProvideAdvice = (adviceObj) => {
const {id,advice} = adviceObj;
adviceNumber.textContent = `ADVICE #${id}`;
adviceQuote.textContent = advice;
};
const generateNewAdvice = async()=> {
const data = await fetchNewAdvice()
const advice = data.slip;
//Render
ProvideAdvice(advice);
};
window.addEventListener('DOMContentLoaded', () => {
fetchBtn.addEventListener('click', generateNewAdvice)
})