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
45 lines (35 loc) · 1.9 KB
/
Copy pathscript.js
File metadata and controls
45 lines (35 loc) · 1.9 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
//TODO: Add Your Code Below
window.addEventListener('load', () => {
fetch('https://handlers.education.launchcode.org/static/astronauts.json')
.then(response => response.json())
.then(data => {
const container = document.getElementById('container');
data.forEach(astronaut => {
const astronautDiv = document.createElement('div');
astronautDiv.classList.add('astronaut');
const bioDiv = document.createElement('div');
bioDiv.classList.add('bio');
const astronautName = document.createElement('h3');
astronautName.textContent = `${astronaut.firstName} ${astronaut.lastName}`;
const astronautInfoList = document.createElement('ul');
const hoursInSpace = document.createElement('li');
hoursInSpace.textContent = `Hours in space: ${astronaut.hoursInSpace}`;
const isActive = document.createElement('li');
isActive.textContent = `Active: ${astronaut.active}`;
const skills = document.createElement('li');
skills.textContent = `Skills: ${astronaut.skills.join(', ')}`;
astronautInfoList.appendChild(hoursInSpace);
astronautInfoList.appendChild(isActive);
astronautInfoList.appendChild(skills);
bioDiv.appendChild(astronautName);
bioDiv.appendChild(astronautInfoList);
const avatarImg = document.createElement('img');
avatarImg.classList.add('avatar');
avatarImg.src = `images/${astronaut.picture}`;
astronautDiv.appendChild(bioDiv);
astronautDiv.appendChild(avatarImg);
container.appendChild(astronautDiv);
});
})
.catch(error => console.error('Error fetching astronaut data:', error));
});