Skip to content

Commit 59aa06b

Browse files
committed
completed fetch exercises
1 parent dbc1afb commit 59aa06b

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

fetch/exercises/fetch_planets.html

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

0 commit comments

Comments
 (0)