File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11function fetchComic ( ) {
22 const container = document . getElementById ( "comic-container" ) ;
3+ const loading = document . getElementById ( "loading" ) ;
34
45 fetch ( "https://xkcd.now.sh/?comic=latest" )
56 . then ( response => {
@@ -11,14 +12,21 @@ function fetchComic() {
1112 . then ( data => {
1213 console . log ( data ) ; // requirement
1314
15+ // remove loading message
16+ if ( loading ) loading . remove ( ) ;
17+
1418 container . innerHTML = `
1519 <h2>${ data . title } </h2>
1620 <img src="${ data . img } " alt="${ data . alt } " />
1721 <p>${ data . alt } </p>
1822 ` ;
1923 } )
2024 . catch ( error => {
21- container . innerHTML = `<p>Error loading comic 😢</p>` ;
25+ if ( loading ) {
26+ loading . textContent = "Error loading comic 😢" ;
27+ } else {
28+ container . innerHTML = `<p>Error loading comic 😢</p>` ;
29+ }
2230 console . error ( error ) ;
2331 } ) ;
2432}
You can’t perform that action at this time.
0 commit comments