-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
39 lines (28 loc) · 856 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
37
38
39
const jokeEl = document.getElementById('joke');
const jokeBtn = document.getElementById('jokebtn');
jokeBtn.addEventListener('click', generateJoke);
generateJoke();
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;
}
//if this block of code beneath is replaced with line 8 to line 20,
//we'll have the exact same outcome.
// function generateJoke() {
// const config = {
// headers: {
// 'Accept': 'application/json'
// }
// }
// fetch ('https://icanhazdadjoke.com/', config)
// .then(res => res.json())
// .then(data => {
// jokeEl.innerHTML = data.joke
// });
// }