File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change 9
9
< body >
10
10
< div class ="container ">
11
11
< 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 >
13
17
< button id ="jokeBtn " class ="btn "> Get Another Joke</ button >
14
18
</ div >
15
19
< script src ="script.js "> </ script >
Original file line number Diff line number Diff line change @@ -2,12 +2,20 @@ const jokeEl = document.getElementById("joke");
2
2
const jokeBtn = document . getElementById ( "jokeBtn" ) ;
3
3
4
4
const generateJoke = async ( ) => {
5
+ // Prevent Multiple Clicks
6
+ jokeBtn . disabled = true ;
7
+ jokeBtn . innerText = "Loading..." ;
5
8
const config = {
6
9
headers : { Accept : "application/json" } ,
7
10
} ;
8
11
const res = await fetch ( "https://icanhazdadjoke.com/" , config ) ;
12
+ // Check API Response Status
13
+ // const res = await fetch("https://icanhazdadjoke.com/nonexistent", config);
9
14
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" ;
11
19
12
20
// Fetching with .then()
13
21
// fetch("https://icanhazdadjoke.com/", config)
Original file line number Diff line number Diff line change 34
34
}
35
35
36
36
.joke {
37
- font-size : 30px ;
37
+ /* Style the Joke Text */
38
+ font-size : 1.875rem ;
38
39
letter-spacing : 1px ;
39
- line-height : 40px ;
40
+ line-height : 1.4 ;
41
+ color : # 333 ;
40
42
margin : 50px auto;
41
43
max-width : 600px ;
42
44
}
59
61
.btn : focus {
60
62
outline : 0 ;
61
63
}
64
+
65
+ /* Prevent Multiple Clicks */
66
+ .btn : disabled {
67
+ opacity : 0.6 ;
68
+ cursor : not-allowed;
69
+ }
You can’t perform that action at this time.
0 commit comments