-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (27 loc) · 819 Bytes
/
app.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
const divJoke = document.querySelector('.joke');
const btn = document.querySelector('.btn');
const configAxios = {
headers: { Accept: 'application/json' }
};
async function dadJokes() {
const res = await axios.get('https://icanhazdadjoke.com/', configAxios);
if (res.data.status != 200) {
const p = document.createElement('p');
p.append(`Server Not Responded. Status Code : ${res.data.status}`);
divJoke.append(p);
}
const p = document.createElement('p');
const joke = res.data.joke;
p.append(joke);
divJoke.append(p);
}
dadJokes().catch((e) => {
const p = document.createElement('p');
p.append(`Something went wrong. ${e}`);
divJoke.append(p);
console.log('Something went wrong, please try again later. ', e);
});
btn.addEventListener('click', () => {
divJoke.innerText = ' ';
dadJokes();
});