File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 8
8
</ head >
9
9
< body >
10
10
< script src ="script.js "> </ script >
11
+
11
12
< h1 > Astronauts</ h1 >
12
13
< div id ="container ">
13
14
<!-- List of astronauts will be added here dynamically -->
Original file line number Diff line number Diff line change 1
- // TODO: add code here
1
+ window . addEventListener ( "load" , function ( ) {
2
+ let json = [ ] ;
3
+ fetch ( "https://handlers.education.launchcode.org/static/astronauts.json" ) . then ( function ( response ) {
4
+ console . log ( response ) ;
5
+ response . json ( ) . then ( function ( json ) {
6
+ const container = document . getElementById ( "container" ) ;
7
+ let index = 0 ;
8
+ container . addEventListener ( "click" , function ( ) {
9
+ container . innerHTML = `
10
+ <div class = "astronaut">
11
+ <div class = "bio">
12
+ <h3>${ json [ index ] . firstName , json [ index ] . lastName } </h3>
13
+ <ul>
14
+ <li>Hours in space: ${ json [ index ] . hoursInSpace } </li>
15
+ <li>Active: ${ json [ index ] . active } </li>
16
+ <li>Skills: ${ json [ index ] . skills } </li>
17
+ </div>
18
+ <img class="avatar" src="images/mae-jemison.jpg">
19
+ </div>
20
+
21
+ ` ;
22
+ index = ( index + 1 ) % json . length ;
23
+ < / div >
24
+ } ) ;
25
+
26
+ } ) ;
27
+ } ) ;
28
+
29
+ } ) ;
You can’t perform that action at this time.
0 commit comments