File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Expand file tree Collapse file tree 3 files changed +55
-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
+
8
+
9
+ // TODO: fetch planets JSON
10
+ fetch ( "https://handlers.education.launchcode.org/static/planets.json" ) . then ( function ( response ) {
11
+ response . json ( ) . then ( function ( json ) {
12
+ const destination = document . getElementById ( "destination" ) ;
13
+ let index = 0 ;
14
+ destination . addEventListener ( "click" , function ( ) {
15
+ destination . innerHTML = `
16
+ <div>
17
+ <h3>Planet ${ json [ index ] . name } </h3>
18
+ <img src=${ json [ index ] . image } height=250></img>
19
+ </div>
20
+ ` ;
21
+ index = ( index + 1 ) % json . length ;
22
+ } ) ;
23
+ } ) ;
24
+
25
+
26
+
27
+ } ) ;
28
+
29
+ } ) ;
30
+ </ script >
31
+ </ head >
32
+ < body >
33
+ < h1 > Destination</ h1 >
34
+ < div id ="destination ">
35
+ < h3 > Planet</ h3 >
36
+ </ div >
37
+ </ body >
38
+ </ html >
Original file line number Diff line number Diff line change @@ -7,14 +7,26 @@ window.addEventListener("load", function() {
7
7
8
8
fetch ( "https://handlers.education.launchcode.org/static/astronauts.json" ) . then ( function ( response ) {
9
9
response . json ( ) . then ( function ( data ) {
10
+
11
+ //sort astronauts by descending order
12
+ data . sort ( ( a , b ) => b . hoursInSpace - a . hoursInSpace ) ;
13
+
14
+ // Select the container to append astronaut cards
15
+ let container = document . getElementById ( "container" ) ;
16
+
10
17
for ( let i = 0 ; i < data . length ; i ++ ) {
11
18
let astronaut = data [ i ] ;
19
+
20
+ // Determine the class for the 'Active' status based on astronaut's active status
21
+ let activeClass = astronaut . active ? "active" : "inactive" ;
22
+
12
23
container . innerHTML += `
13
24
<div class="astronaut">
14
25
<div class="bio">
15
26
<h3>${ astronaut . firstname } ${ astronaut . lastName } </h3>
16
27
<ul>
17
28
<li>Hours in space: ${ astronaut . hoursInSpace } </li>
29
+ <li>class= "${ activeClass } >Active: ${ astronaut . active } </li>
18
30
<li>Active: ${ astronaut . active } </li>
19
31
<li>Skills: ${ astronaut . skills } </li>
20
32
</ul>
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
+ }
21
+
You can’t perform that action at this time.
0 commit comments