Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update index.html #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Astronauts</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script src="script.js"></script>
<h1>Astronauts</h1>
<div id="container">
<!-- List of astronauts will be added here dynamically -->
</div>
</body>
</html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Astronauts</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script src="script.js"></script>
<h1>Astronauts</h1>
<h2 id="count"></h2>
<div id="container">
<!-- List of astronauts will be added here dynamically -->
</div>
</body>
</html>
33 changes: 32 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
// TODO: add code here
// TODO: add code here
window.addEventListener("load",function(){
fetch("https://handlers.education.launchcode.org/static/astronauts.json").then(function(response){
console.log(response)
response.json().then(function(json){
console.log(json);
let astronauts = "";
let counter = 0;
let container = document.getElementById("container");
for(astronaut of json){
console.log(astronaut);
astronauts +=`<div class="astronaut">
<div class="bio">
<h3>${astronaut.firstName} ${astronaut.lastName}</h3>
<ul>
<li>Hours in space: ${astronaut.hoursInSpace}</li>
<li>Active: ${astronaut.active}</li>
<li>Skills:${astronaut.skills}</li>
<li>Skills:${astronaut.skills.join(', ')}</li>
</ul>
</div>
<img class="avatar" src="${astronaut.picture}">
</div>`
counter++
}
let count = document.getElementById("count");
count.innerHTML = `<h3>Count: ${counter}</h3>`
container.innerHTML = astronauts;
})

})
})