Skip to content

Commit 198842b

Browse files
committed
random joke generator
1 parent b56eccb commit 198842b

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
57.6 KB
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Random Joke Generator</title>
7+
<link rel="stylesheet" href="style.css">
8+
<script defer src="script.js"></script>
9+
</head>
10+
<body>
11+
<div class="container">
12+
<div class="laughing-emoji">😂
13+
<div class="joke" id="joke">Loading.....</div>
14+
<button class="newJokeBtn">New Joke</button>
15+
</div>
16+
</div>
17+
</body>
18+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const joke = document.getElementById('joke');
2+
const newJokeBtn = document.querySelector('.newJokeBtn');
3+
const url = "https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist,sexist,explicit&type=single"
4+
5+
let getJoke = () => {
6+
// fetch(url).then(data => data.json()).then(item => console.log(item.joke))
7+
fetch(url).then(data => data.json()).then(item => {
8+
joke.innerHTML = item.joke;
9+
})
10+
}
11+
getJoke();
12+
13+
newJokeBtn.addEventListener('click', getJoke);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
* {
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
background-color: #e6a020;
9+
display: flex;
10+
justify-content: center;
11+
align-items: center;
12+
height: 100vh;
13+
font-family: sans-serif;
14+
}
15+
16+
.laughing-emoji {
17+
font-size: 10rem;
18+
background-color: rgba(0, 0, 0, 0.712);
19+
padding: 1px 100px 10px 100px;
20+
border-radius: 10px;
21+
display: flex;
22+
flex-direction: column;
23+
align-items: center;
24+
justify-content: center;
25+
position: absolute;
26+
left: 50%;
27+
top: 50%;
28+
transform: translate(-50%, -50%);
29+
}
30+
31+
.joke {
32+
font-size: 2rem;
33+
color: white;
34+
padding: 20px;
35+
36+
}
37+
38+
.newJokeBtn {
39+
padding: 10px 20px;
40+
font-size: 1.5rem;
41+
background-color: #e6a020;
42+
color: white;
43+
border: none;
44+
border-radius: 5px;
45+
cursor: pointer;
46+
}

0 commit comments

Comments
 (0)