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
52 lines (39 loc) · 1.94 KB
/
Copy pathscript.js
File metadata and controls
52 lines (39 loc) · 1.94 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
46
47
48
49
50
51
52
// TODO: Add Your Code Below
window.addEventListener("load", function () {
fetch("https://handlers.education.launchcode.org/static/astronauts.json")
.then(response => response.json())
.then(data => {
const astronauts = data;
const container = document.querySelector("#container");
astronauts.forEach(astronaut => {
const astronautDiv = document.createElement("div");
astronautDiv.classList.add("astronaut");
const bioDiv = document.createElement("div");
bioDiv.classList.add("bio");
const h3 = document.createElement("h3");
h3.textContent = `${astronaut.firstName} ${astronaut.lastName}`;
const ul = document.createElement("ul");
const hoursLi = document.createElement("li");
hoursLi.textContent = `Hours in space: ${astronaut.hoursInSpace}`;
const activeLi = document.createElement("li");
activeLi.textContent = `Active: ${astronaut.active ? "true" : "false"}`;
const skillsLi = document.createElement("li");
skillsLi.textContent = `Skills: ${astronaut.skills.join(", ")}`;
const avatarImg = document.createElement("img");
avatarImg.classList.add("avatar");
avatarImg.src = astronaut.picture;
avatarImg.alt = `${astronaut.firstName} ${astronaut.lastName}`;
ul.appendChild(hoursLi);
ul.appendChild(activeLi);
ul.appendChild(skillsLi);
bioDiv.appendChild(h3);
bioDiv.appendChild(ul);
astronautDiv.appendChild(bioDiv);
astronautDiv.appendChild(avatarImg);
container.appendChild(astronautDiv);
});
})
.catch(error => {
console.error("Error fetching data:", error);
});
});