-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (36 loc) · 1.36 KB
/
index.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
43
44
45
let btn = document.getElementById("get_joke");
let joke = document.getElementById('joke');
let loading;
let loading_animation = document.getElementById('loading')
window.addEventListener('load', () => {
loading = true;
checkloading();
getjoke();
})
btn.addEventListener('click', () => {
loading = true;
checkloading()
getjoke();
})
function getjoke() {
let url = "https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,sexist,explicit&type=single"
fetch(url)
.then(response => response.json())
.then((data) => {
loading = false;
loading_animation.style.display = 'none'
console.log(data.joke);
joke.innerHTML = data.joke;
joke.style.textAlign = 'left';
});
// .catch(console.log('Something Error'))
}
checkloading = () => {
if (loading = true) {
console.log("loading")
loading_animation.style.visibility = 'visible'
loading_animation.style.display = 'block'
joke.innerHTML = "Loading";
joke.style.textAlign = 'center';
}
}