Skip to content

Commit b316036

Browse files
update Dad Joke Generator project
1 parent 420c6ab commit b316036

File tree

7 files changed

+109
-1674
lines changed

7 files changed

+109
-1674
lines changed
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 http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Dad Joke Generator</title>
8+
<link rel="stylesheet" href="style.css" />
9+
</head>
10+
<body>
11+
<div class="container">
12+
<h1 class="heading">Dad Joke Generator</h1>
13+
<h2 class="joke" id="joke">Dad Joke</h2>
14+
<button class="btn" id="btn">Tell me a joke</button>
15+
</div>
16+
<script src="index.js"></script>
17+
</body>
18+
</html>

projects/dad-jokes-generator/index.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const btnEl = document.getElementById("btn");
2+
const jokeEl = document.getElementById("joke");
3+
4+
const apiKey = "SAXb3lrT9IIorMjQkAFWBg==KCDQCZgWgcoAU4ai";
5+
6+
const options = {
7+
method: "GET",
8+
headers: {
9+
"X-Api-Key": apiKey,
10+
},
11+
};
12+
13+
const apiURL = `https://api.api-ninjas.com/v1/dadjokes?limit=1`;
14+
15+
async function getJoke() {
16+
try {
17+
btnEl.innerText = "Loading...";
18+
btnEl.disabled = true;
19+
jokeEl.innerText = "Updating...";
20+
const response = await fetch(apiURL, options);
21+
const data = await response.json();
22+
const jokeContent = data[0].joke;
23+
jokeEl.innerText = jokeContent;
24+
btnEl.innerText = "Tell me a joke";
25+
btnEl.disabled = false;
26+
console.log(data);
27+
} catch (error) {
28+
console.log(error);
29+
jokeEl.innerText = "An error happened, try again later";
30+
btnEl.innerText = "Tell me a joke";
31+
btnEl.disabled = false;
32+
}
33+
}
34+
35+
getJoke();
36+
37+
btnEl.addEventListener("click", getJoke);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
body {
2+
margin: 0;
3+
display: flex;
4+
min-height: 100vh;
5+
justify-content: center;
6+
align-items: center;
7+
font-family: monospace;
8+
background: linear-gradient(to left bottom, lightblue, lightpink, lightblue);
9+
}
10+
11+
.container {
12+
background-color: rgba(255, 255, 255, 0.3);
13+
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
14+
padding: 20px;
15+
border-radius: 15px;
16+
width: 85%;
17+
text-align: center;
18+
color: darkgreen;
19+
}
20+
21+
.heading {
22+
font-size: 35px;
23+
font-weight: 200;
24+
font-family: Impact;
25+
letter-spacing: 2px;
26+
27+
text-shadow: 5px 5px 2px rgba(0, 0, 0, 0.3);
28+
}
29+
30+
.joke {
31+
font-size: 25px;
32+
font-weight: 500;
33+
margin: 40px;
34+
}
35+
36+
.btn {
37+
font-size: 18px;
38+
font-weight: 700;
39+
border-radius: 5px;
40+
cursor: pointer;
41+
padding: 10px;
42+
margin-top: 15px;
43+
background-color: rgba(255, 255, 255, 0.3);
44+
border-color: rgba(255, 255, 255, 0.6);
45+
text-transform: uppercase;
46+
width: 300px;
47+
color: darkgreen;
48+
}
49+
50+
.btn:hover {
51+
background-color: rgba(255, 255, 255, 0.5);
52+
box-shadow: 0 4px 4px rgba(0, 0, 0, 0.3);
53+
transition: all 300ms ease;
54+
}

projects/project-idea-generator/index.html

Lines changed: 0 additions & 43 deletions
This file was deleted.

projects/project-idea-generator/src/css/styles.css

Lines changed: 0 additions & 102 deletions
This file was deleted.

projects/project-idea-generator/src/js/main.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy