Skip to content

Commit 25e4101

Browse files
committed
feat: day 10
1 parent 4a95abf commit 25e4101

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

010-dad jokes/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
<body>
1010
<div class="container">
1111
<h3>Don't Laugh Challenge</h3>
12-
<div id="joke" class="joke">// Joke goes here</div>
12+
<!-- Experiment with Network Failure -->
13+
<!-- <div id="joke" class="joke">// Joke goes here</div> -->
14+
<div id="joke" class="joke">
15+
Hmm, our joke delivery service seems to be on coffee break
16+
</div>
1317
<button id="jokeBtn" class="btn">Get Another Joke</button>
1418
</div>
1519
<script src="script.js"></script>

010-dad jokes/script.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ const jokeEl = document.getElementById("joke");
22
const jokeBtn = document.getElementById("jokeBtn");
33

44
const generateJoke = async () => {
5+
// Prevent Multiple Clicks
6+
jokeBtn.disabled = true;
7+
jokeBtn.innerText = "Loading...";
58
const config = {
69
headers: { Accept: "application/json" },
710
};
811
const res = await fetch("https://icanhazdadjoke.com/", config);
12+
// Check API Response Status
13+
// const res = await fetch("https://icanhazdadjoke.com/nonexistent", config);
914
const data = await res.json();
10-
jokeEl.innerHTML = data.joke;
15+
jokeEl.innerHTML = res.status === 200 ? data.joke : "No joke found!";
16+
17+
jokeBtn.disabled = false;
18+
jokeBtn.innerText = "Get Another Joke";
1119

1220
// Fetching with .then()
1321
// fetch("https://icanhazdadjoke.com/", config)

010-dad jokes/style.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ h3 {
3434
}
3535

3636
.joke {
37-
font-size: 30px;
37+
/* Style the Joke Text */
38+
font-size: 1.875rem;
3839
letter-spacing: 1px;
39-
line-height: 40px;
40+
line-height: 1.4;
41+
color: #333;
4042
margin: 50px auto;
4143
max-width: 600px;
4244
}
@@ -59,3 +61,9 @@ h3 {
5961
.btn:focus {
6062
outline: 0;
6163
}
64+
65+
/* Prevent Multiple Clicks */
66+
.btn:disabled {
67+
opacity: 0.6;
68+
cursor: not-allowed;
69+
}

0 commit comments

Comments
 (0)