forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (37 loc) · 1.57 KB
/
Copy pathscript.js
File metadata and controls
38 lines (37 loc) · 1.57 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
//TODO: Add Your Code Below
window.addEventListener("load", () => {
fetch("https://handlers.education.launchcode.org/static/astronauts.json").then((response) => {
response.json().then((json) => {
console.log(json);
let jsonSort = [];
let jsonLength = json.length;
for (let i = 0; i < jsonLength; i++) {
let temp = 0;
for (let j = 0; j < json.length; j++) {
if (json[j].hoursInSpace > json[temp].hoursInSpace) {
temp = j;
}
}
jsonSort.push(json[temp]);
json.splice(temp,1);
}
let oldDiv = document.getElementById("container");
oldDiv.innerHTML += `Total astronauts listed: ${jsonSort.length}`;
for (let i = 0; i < jsonSort.length; i++) {
let activity = jsonSort[i].active ? ' style="color:green"' : '';
oldDiv.innerHTML += `
<div class="astronaut">
<div class="bio">
<h3>${jsonSort[i].firstName} ${jsonSort[i].lastName}</h3>
<ul>
<li>Hours in space: ${jsonSort[i].hoursInSpace}</li>
<li${activity}>Active: ${jsonSort[i].active}</li>
<li>Skills: ${jsonSort[i].skills.join(", ")}</li>
</ul>
</div>
<img class="avatar" src=${jsonSort[i].picture}>
</div>`
}
});
});
});