File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99 < body >
1010 < script src ="script.js "> </ script >
1111 < h1 > Astronauts</ h1 >
12+
13+ <!-- Bonus mission 3 -->
14+ < div id ="count "> </ div >
15+
1216 < div id ="container ">
1317 <!-- List of astronauts will be added here dynamically -->
1418 </ div >
Original file line number Diff line number Diff line change 11//TODO: Add Your Code Below
2+ window . addEventListener ( "load" , function ( ) {
3+ // TODO; create object for container element
4+ const container = document . getElementById ( "container" ) ;
5+
6+ // Fetch using traditional syntax
7+ fetch (
8+ "https://handlers.education.launchcode.org/static/astronauts.json"
9+ ) . then ( function ( response ) {
10+ response . json ( ) . then ( function ( data ) {
11+ console . log ( data ) ;
12+
13+ // Bonus mission 1
14+ data . sort ( function ( a , b ) {
15+ return a . hoursInSpace < b . hoursInSpace ? 1 : - 1 ;
16+ } ) ;
17+
18+ // Bonus mission 3
19+ const count = document . getElementById ( 'count' ) ;
20+ count . innerHTML = `These ${ data . length } people have ventured into outer space.`
21+
22+ for ( let i = 0 ; 0 < data . length ; i ++ ) {
23+ let astronaut = data [ i ] ;
24+
25+ // Bonus mission 2
26+ let activeClass = astronaut . active ? "active" : "" ;
27+
28+
29+ container . innerHTML += `
30+ <div class = "astronaut">
31+ <div class = "bio">
32+ <h3>${ astronaut . firstName } ${ astronaut . lastName } </h3>
33+ <ul>
34+ <li>Hours in space: ${ astronaut . hoursInSpace } </li>
35+ <li class = ${ activeClass } >Active: ${ astronaut . active } </li>
36+ <li>Skills: ${ astronaut . skills . join ( ", " ) } </li>
37+ </ul>
38+ </div>
39+ <img class = "avatar" src = "${ astronaut . picture } "
40+ </div>
41+ ` ;
42+ }
43+ } ) ;
44+ } ) ;
45+ } ) ;
Original file line number Diff line number Diff line change 1414 margin-bottom : 20px ;
1515 border-radius : 6px ;
1616}
17+
18+ .active {
19+ color : green;
20+ }
You can’t perform that action at this time.
0 commit comments