-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
26 lines (22 loc) · 840 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
const API_LINK = "https://api.adviceslip.com/advice";
const adviceNumberSpan = document.querySelector('.advice-generator__advice-number');
const adviceQuoteSlot = document.querySelector('.advice-generator__quote');
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 renderAdvice = (adviceObj) => {
const { id, advice } = adviceObj;
adviceNumberSpan.textContent = `ADVICE #${id}`;
adviceQuoteSlot.textContent = advice;
};
const generateNewAdvice = async () => {
const data = await fetchNewAdvice();
const advice = data.slip;
renderAdvice(advice)
};
window.addEventListener('DOMContentLoaded', () => {
fetchBtn.addEventListener('click', generateNewAdvice)
})