forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_planets.html
More file actions
33 lines (33 loc) · 1.05 KB
/
fetch_planets.html
File metadata and controls
33 lines (33 loc) · 1.05 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fetch Planets</title>
<script>
window.addEventListener("load", function(){
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>