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
32 lines (31 loc) · 1.31 KB
/
script.js
File metadata and controls
32 lines (31 loc) · 1.31 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
window.addEventListener("load",function(){
fetch("https://handlers.education.launchcode.org/static/astronauts.json").then(function(response){
return response.json()
})
.then(function(response){
response.sort((a,b) => (a.hoursInSpace > b.hoursInSpace) ? 1 : -1)
console.log(response);
containerHTML = document.getElementById("container")
for (let i = 0; i < response.length; i++){
containerHTML.innerHTML += `
<div class="astronaut">
<div class="bio">
<h3>${response[i].firstName} ${response[i].lastName}</h3>
<ul>
<li>Hours in space: ${response[i].hoursInSpace}</li>
<li id="active">Active: ${response[i].active}</li>
<li>Skills: ${response[i].skills}</li>
</ul>
</div>
<img class="avatar" src="${response[i].picture}" />
</div>
`;
let status = document.getElementById("active");
if (status.innerHTML === "Active: true"){
status.id = "activeTrue";
};
}
let astroCount = this.document.getElementById("astroCount");
astroCount.innerHTML = `Astronaut Count: ${response.length}`;
});
});