File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,29 @@ window.addEventListener("load", function () {
14
14
const container = document . getElementById ( "container" ) ;
15
15
16
16
// Using a For Loop to iterated through each object in the array in json
17
+ let activeAstronauts = 0
18
+
17
19
for ( let i = 0 ; i < json . length ; i ++ ) {
18
- container . innerHTML += `
20
+
21
+ if ( json [ i ] . active ) {
22
+ activeAstronauts += 1 ;
23
+ container . innerHTML += `
24
+ <div class="astronaut">
25
+ <div class="bio">
26
+ <h3>${ json [ i ] . firstName } ${ json [ i ] . lastName } </h3>
27
+ <ul>
28
+ <li>Hours in space: ${ json [ i ] . hoursInSpace } </li>
29
+ <li class="active">Active: ${ json [ i ] . active } </li>
30
+ <li>Skills: ${ json [ i ] . skills } </li>
31
+ </ul>
32
+ </div>
33
+ <img class="avatar" src="${ json [ i ] . picture } ">
34
+ </div>
35
+
36
+
37
+ `
38
+ } else {
39
+ container . innerHTML += `
19
40
<div class="astronaut">
20
41
<div class="bio">
21
42
<h3>${ json [ i ] . firstName } ${ json [ i ] . lastName } </h3>
@@ -27,8 +48,17 @@ window.addEventListener("load", function () {
27
48
</div>
28
49
<img class="avatar" src="${ json [ i ] . picture } ">
29
50
</div>
51
+
30
52
`
53
+ }
31
54
}
55
+
56
+ container . innerHTML += `
57
+ <p>
58
+ Total Number of Astronauts: ${ json . length } <br>
59
+ <span class="active">Total ACTIVE Astronauts: ${ activeAstronauts } </span>
60
+ </p>
61
+ `
32
62
} ) ;
33
63
} ) ;
34
64
} ) ;
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