Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
A lazy commit.
  • Loading branch information
Jason L Perry committed Aug 7, 2017
1 parent 6aad53f commit 09bf92f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<link rel="stylesheet" href="/screen.css">
</head>
<body>
<h1>Hello, World!</h1>
<h1>Adventure Time</h1>
<ul>
</ul>
<div class="details">
</div>
<script src="main.js" charset="utf-8"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions public/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const ul = document.querySelector('ul')
const details = document.querySelector('.details')

const getCharacterDetails = (id) => {
fetch(`http://localhost:3000/characters/${id}`).then(res => res.json()).then(data => {
const template = `
<h2>${data.name}</h2>
<p>${data.bio}</p>
<img src="${data.image}" alt="">
`
details.innerHTML = template
})
}

fetch('http://localhost:3000/characters').then(res => res.json()).then(data => {
data.forEach((character) => {
const li = document.createElement('li')
const a = document.createElement('a')
a.textContent = character.name
li.appendChild(a)
ul.appendChild(li)
a.addEventListener('click', () => {
getCharacterDetails(character.id)
})
})
})

0 comments on commit 09bf92f

Please sign in to comment.