-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathjokeGenerator.html
More file actions
68 lines (57 loc) · 1.63 KB
/
jokeGenerator.html
File metadata and controls
68 lines (57 loc) · 1.63 KB
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
66
67
68
<!DOCTYPE html>
<html>
<head>
<title>Joke Generator</title>
<style type="text/css" media="all">
body{
height: 100vh;
display: grid;
place-items: center;
}
section{
display:flex;
flex-direction:column;
align-items:center;
width: 300px;
padding: 10px;
background: #d4e0ff;
border-radius: 5px;
}
div{
background: dodgerblue;
padding: 10px;
border-radius: 5px;
text-align: center;
color: white;
font-size:20px;
}
#gen-btn:hover{
cursor:pointer;
}
</style>
</head>
<body>
<section>
<h2>Joke Generator</h2>
<p></p>
<div id="gen-btn">
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>