Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created November 28, 2019 06:00
Show Gist options
  • Select an option

  • Save harrisonmalone/0369336863843ca0c0ac458c5d302eb2 to your computer and use it in GitHub Desktop.

Select an option

Save harrisonmalone/0369336863843ca0c0ac458c5d302eb2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="characters"></div>
<script src="./script.js"></script>
</body>
</html>
const request = fetch("https://swapi.co/api/people/")
const div = document.querySelector('#characters')
request.then(function(response) {
const getJson = response.json()
getJson.then((json) => {
const characters = json.results
characters.forEach((character) => {
const characterDiv = `
<div>
<p style="color: blue">${character.name}</p>
<p>${character.height}</p>
<hr>
</div>
`
div.insertAdjacentHTML("afterbegin", characterDiv)
});
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment