forked from LaunchCodeEducation/Fetch-and-JSON-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (41 loc) · 1.8 KB
/
script.js
File metadata and controls
45 lines (41 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
window.addEventListener("load", function(){
fetch("https://handlers.education.launchcode.org/static/astronauts.json").then(function(response){
return response.json();
}).then(function(json){
// console.log(json)
let complete ="";
const sorted = json.sort((a, b) => (a.hoursInSpace < b.hoursInSpace) ? 1 : -1);
let container = document.querySelector("#container");
// console.log(container);
for(astro of json){
if(astro.active){
complete += `
<div class="astronaut">
<div class="bio">
<h3>${astro.firstName} ${astro.lastName}</h3>
<ul>
<li>Hours in space: ${astro.hoursInSpace}</li>
<li style="color: green"; >Active: ${astro.active}</li>
<li>Skills: ${astro.skills.join(", ")}</li>
</ul>
</div>
<img class="avatar" src="${astro.picture}"/>
</div>`;
}else{
complete += `
<div class="astronaut">
<div class="bio">
<h3>${astro.firstName} ${astro.lastName}</h3>
<ul>
<li>Hours in space: ${astro.hoursInSpace}</li>
<li>Active: ${astro.active}</li>
<li>Skills: ${astro.skills.join(", ")}</li>
</ul>
</div>
<img class="avatar" src="${astro.picture}"/>
</div>`;
}
}
container.innerHTML = complete;
});
});