-
Notifications
You must be signed in to change notification settings - Fork 7
/
jokes.js
36 lines (30 loc) · 1.08 KB
/
jokes.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 API_URL = "https://icanhazdadjoke.com"
if (navigator.onLine) {
const request_new_joke = async () => {
const joke = await fetch(API_URL, {
method: "GET",
headers: { "Accept": "application/json" }
})
.then((response) => response.json())
.then((response) => response.joke)
.catch((err) => {
err
})
document.getElementById('joke').innerText = joke
}
document.addEventListener("DOMContentLoaded", () => {
request_new_joke()
})
document.getElementById('new').addEventListener("click", () => {
request_new_joke()
document.getElementById('like').style.backgroundColor = "rgb(88, 221, 245)"
document.getElementById('like').innerText = "Like"
})
document.getElementById('like').addEventListener("click", () => {
document.getElementById('like').style.backgroundColor = "#008CBA"
document.getElementById('like').innerText = "Liked"
})
}
else{
document.getElementById('joke').innerText = "No Internet Connection"
}