File tree 4 files changed +38
-0
lines changed
hyperskill/07_dog_glossary/01
4 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ window . onload = function ( ) {
2
+ const randomDogButton = document . getElementById ( 'button-random-dog' ) ;
3
+ const contentDiv = document . getElementById ( 'content' ) ;
4
+
5
+ const dogApiBaseUrl = 'https://dog.ceo/api' ;
6
+
7
+ randomDogButton . addEventListener ( 'click' , async function ( ) {
8
+ const response = await fetch ( `${ dogApiBaseUrl } /breeds/image/random` ) ;
9
+
10
+ if ( ! response . ok ) {
11
+ contentDiv . innerHTML = 'Error fetching random dog' ;
12
+ return ;
13
+ }
14
+
15
+ const data = await response . json ( ) ;
16
+
17
+ if ( data . status === 'success' ) {
18
+ contentDiv . innerHTML = `<img src="${ data . message } " alt="Random dog" />` ;
19
+ }
20
+ } ) ;
21
+ }
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < title > Dog Glossary</ title >
6
+ < link rel ="stylesheet " href ="style.css ">
7
+ < script src ="app.js " defer > </ script >
8
+ </ head >
9
+ < body >
10
+ < h1 > Dog Glossary</ h1 >
11
+ < button id ="button-random-dog "> Show Random Dog</ button >
12
+ < div id ="content "> </ div >
13
+ </ body >
14
+ </ html >
Original file line number Diff line number Diff line change
1
+ * {
2
+ box-sizing : border-box;
3
+ }
You can’t perform that action at this time.
0 commit comments