File tree 3 files changed +52
-0
lines changed
3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 9
9
< body >
10
10
< script src ="script.js "> </ script >
11
11
< h1 > Astronauts</ h1 >
12
+
13
+ <!-- Bonus mission 3 -->
14
+ < div id ="count "> </ div >
15
+
12
16
< div id ="container ">
13
17
<!-- List of astronauts will be added here dynamically -->
14
18
</ div >
Original file line number Diff line number Diff line change 1
1
//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 14
14
margin-bottom : 20px ;
15
15
border-radius : 6px ;
16
16
}
17
+
18
+ .active {
19
+ color : green;
20
+ }
You can’t perform that action at this time.
0 commit comments