Skip to content

Commit 2189fea

Browse files
committed
fetch studio
1 parent 1b0c334 commit 2189fea

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

fetch/studio/script.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
11
//TODO: Add Your Code Below
2+
function init() {
3+
4+
fetch('https://handlers.education.launchcode.org/static/astronauts.json')
5+
.then(response => response.json())
6+
.then(data => {
7+
data.sort((a, b) => b.hoursInSpace - a.hoursInSpace);
8+
9+
const astronautCount = document.createElement('h2');
10+
const container = document.getElementById('container');
11+
astronautCount.textContent = `Total Number of Astronauts: ${data.length}`;
12+
document.body.insertBefore(astronautCount, container);
13+
14+
data.forEach(astronaut => {
15+
let activeText = `Active: ${astronaut.active}`;
16+
if (astronaut.active) {
17+
activeText = `<span style="color: green;">Active: ${astronaut.active}</span>`;
18+
}
19+
20+
const astronautHTML = `
21+
<div class="astronaut">
22+
<div class="bio">
23+
<h3>${astronaut.firstName} ${astronaut.lastName}</h3>
24+
<ul>
25+
<li>Hours in space: ${astronaut.hoursInSpace}</li>
26+
<li>${activeText}</li>
27+
<li>Skills: ${astronaut.skills.join(', ')}</li>
28+
</ul>
29+
</div>
30+
<img class="avatar" src="${astronaut.picture}">
31+
</div>
32+
`;
33+
container.innerHTML += astronautHTML;
34+
});
35+
})
36+
37+
}
38+
39+
window.addEventListener('load', init);

fetch/studio/style.css

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,24 @@
1010
justify-content: space-between;
1111
width: 500px;
1212
align-items: center;
13-
padding: 5px;
13+
padding: 10px;
1414
margin-bottom: 20px;
1515
border-radius: 6px;
16+
box-shadow: 5px 5px 10px rgba(75, 75, 75, 0.392);
17+
background-color: white;
1618
}
19+
20+
#container {
21+
margin: 0 auto;
22+
max-width: 80%;
23+
24+
}
25+
26+
h1 ,h2 {
27+
text-align: center;
28+
}
29+
30+
body {
31+
font-family: Arial, Helvetica, sans-serif;
32+
background-image: linear-gradient(rgb(255, 197, 88), rgb(0, 0, 148));
33+
}

0 commit comments

Comments
 (0)