-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
45 lines (32 loc) · 825 Bytes
/
main.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
// variables
const adviceQuote = document.querySelector('#advice-quote')
const adviceID = document.querySelector('#advice-id')
const apiURL = 'https://api.adviceslip.com/advice'
const returnID = 'https://api.adviceslip.com/advice'
const randomBtn = document.querySelector('#btn-random')
window.onload = () => {
getQuotes()
getID()
}
randomBtn.addEventListener('click', () => {
getQuotes()
getID()
})
function get(url) {
return fetch(url).then((respsonse) => respsonse.json())
}
const api = {
get,
}
function getID() {
api.get(returnID).then((data) => showID(data['slip']['id']))
}
function getQuotes() {
api.get(apiURL).then((data) => showQuote(data['slip']['advice']))
}
function showID(id) {
adviceID.innerHTML = id
}
function showQuote(quote) {
adviceQuote.innerHTML = quote
}