forked from bradtraversy/50projects50days
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
36 lines (28 loc) · 731 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
30
31
32
33
34
35
36
const jokeEl = document.getElementById('joke')
const jokeBtn = document.getElementById('jokeBtn')
jokeBtn.addEventListener('click', generateJoke)
generateJoke()
// USING ASYNC/AWAIT
async function generateJoke() {
const config = {
headers: {
Accept: 'application/json',
},
}
const res = await fetch('https://icanhazdadjoke.com', config)
const data = await res.json()
jokeEl.innerHTML = data.joke
}
// USING .then()
// function generateJoke() {
// const config = {
// headers: {
// Accept: 'application/json',
// },
// }
// fetch('https://icanhazdadjoke.com', config)
// .then((res) => res.json())
// .then((data) => {
// jokeEl.innerHTML = data.joke
// })
// }