File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < title > Fetch Planets</ title >
5
+ < script >
6
+ window . addEventListener ( "load" , function ( ) {
7
+ // TODO: fetch planets JSON
8
+ fetch ( "https://handlers.education.launchcode.org/static/planets.json" ) . then ( function ( response ) {
9
+ response . json ( ) . then ( function ( json ) {
10
+ const destination = document . getElementById ( "destination" ) ;
11
+ let index = 0 ;
12
+ destination . addEventListener ( "click" , function ( ) {
13
+ destination . innerHTML = `
14
+ <div>
15
+ <h3>Planet ${ json [ index ] . name } </h3>
16
+ <img src=${ json [ index ] . image } height=250></img>
17
+ </div>
18
+ ` ;
19
+ index = ( index + 1 ) % json . length ;
20
+ } ) ;
21
+ } ) ;
22
+ } ) ;
23
+ } ) ;
24
+ </ script >
25
+ </ head >
26
+ < body >
27
+ < h1 > Destination</ h1 >
28
+ < div id ="destination ">
29
+ < h3 > Planet</ h3 >
30
+ </ div >
31
+ </ body >
32
+ </ html >
You can’t perform that action at this time.
0 commit comments