-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch_planets.html
32 lines (32 loc) · 1005 Bytes
/
fetch_planets.html
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
<!DOCTYPE html>
<html>
<head>
<title>Fetch Planets</title>
<script>
window.addEventListener("load", function() {
let json = [];
fetch("https://handlers.education.launchcode.org/static/planets.json").then(function(response) {
response.json().then(function(json) {
const destination = document.getElementById("destination");
let index = 0;
destination.addEventListener("click", function(){
destination.innerHTML = `
<div>
<h3>Planet ${json[index].name}</h3>
<img src=${json[index].image} height=250></img>
</div>
`;
index = (index + 1) % json.length;
});
});
});
});
</script>
</head>
<body>
<h1>Destination</h1>
<div id="destination">
<h3>Planet</h3>
</div>
</body>
</html>