Skip to content

Commit cb5befe

Browse files
committed
program changes planets when clicked on
1 parent cdabec8 commit cb5befe

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

fetch/fetch_planets.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Fetch Planets</title>
5+
<script>
6+
window.addEventListener("load", function(){
7+
8+
9+
// TODO: fetch planets JSON
10+
fetch("https://handlers.education.launchcode.org/static/planets.json").then(function(response){
11+
response.json().then(function(json) {
12+
const destination = document.getElementById("destination");
13+
let index = 0;
14+
destination.addEventListener("click", function(){
15+
destination.innerHTML = `
16+
<div>
17+
<h3>Planet ${json[index].name}</h3>
18+
<img src=${json[index].image} height=250></img>
19+
</div>
20+
`;
21+
index = (index + 1) % json.length;
22+
});
23+
});
24+
25+
26+
27+
});
28+
29+
});
30+
</script>
31+
</head>
32+
<body>
33+
<h1>Destination</h1>
34+
<div id="destination">
35+
<h3>Planet</h3>
36+
</div>
37+
</body>
38+
</html>

fetch/studio/script.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,26 @@ window.addEventListener("load", function() {
77

88
fetch("https://handlers.education.launchcode.org/static/astronauts.json").then(function(response){
99
response.json().then(function(data){
10+
11+
//sort astronauts by descending order
12+
data.sort((a, b) => b.hoursInSpace - a.hoursInSpace);
13+
14+
// Select the container to append astronaut cards
15+
let container = document.getElementById("container");
16+
1017
for (let i=0; i<data.length; i++){
1118
let astronaut = data[i];
19+
20+
// Determine the class for the 'Active' status based on astronaut's active status
21+
let activeClass = astronaut.active ? "active" : "inactive";
22+
1223
container.innerHTML +=`
1324
<div class="astronaut">
1425
<div class="bio">
1526
<h3>${astronaut.firstname} ${astronaut.lastName}</h3>
1627
<ul>
1728
<li>Hours in space: ${astronaut.hoursInSpace}</li>
29+
<li>class= "${activeClass}>Active: ${astronaut.active}</li>
1830
<li>Active: ${astronaut.active}</li>
1931
<li>Skills: ${astronaut.skills}</li>
2032
</ul>

fetch/studio/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@
1414
margin-bottom: 20px;
1515
border-radius: 6px;
1616
}
17+
18+
.active {
19+
color: green;
20+
}
21+

0 commit comments

Comments
 (0)