forked from lancertech6/Hactober2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjokeGenerator.html
65 lines (49 loc) · 1.07 KB
/
jokeGenerator.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html>
<head>
<title>Joke Generator</title>
<style type="text/css" media="all">
body {
height: 100vh;
display: grid;
place-items: center;
}
section {
width: 300px;
padding: 10px;
background: #d4e0ff;
border-radius: 5px;
}
div {
background: dodgerblue;
padding: 10px;
border-radius: 5px;
text-align: center;
}
</style>
</head>
<body>
<section>
<h2>Joke Generator</h2>
<p></p>
<div>
Generate
</div>
</section>
<script type="text/javascript" charset="utf-8">
const elm = document.querySelector('p');
const btn = document.querySelector('div');
async function loadJoke() {
const jokeData = await fetch('https://icanhazdadjoke.com/', {
headers: {
Accept: "application/json"
}
})
.then(response => response.json())
elm.innerHTML = jokeData.joke;
}
window.addEventListener("DOMContentLoaded", loadJoke);
btn.addEventListener("click", loadJoke);
</script>
</body>
</html>