-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathindex.html
More file actions
51 lines (49 loc) · 1.31 KB
/
index.html
File metadata and controls
51 lines (49 loc) · 1.31 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.box {
width: 40%;
border-radius: 10px;
padding: 10px;
box-shadow: 0px 0px 10px 0px gray;
display: flex;
flex-direction: column;
align-items: center;
}
p {
text-align: center;
font-family: cursive;
}
</style>
</head>
<body>
<div class="body">
<div class="box">
<p>Loading...</p>
<button>Generate a Cat fact</button>
</div>
</div>
<script>
const catfactgetter = document.querySelector("p");
const btn = document.querySelector("button");
function loadCatFact() {
fetch("https://catfact.ninja/fact")
.then((response) => response.json())
.then((response) => (catfactgetter.innerHTML = response.fact));
}
window.onload = loadCatFact;
btn.addEventListener("click", loadCatFact);
</script>
</body>
</html>