forked from vnmrsharma/Treehacks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal-index.js
More file actions
41 lines (34 loc) · 860 Bytes
/
local-index.js
File metadata and controls
41 lines (34 loc) · 860 Bytes
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
34
35
36
37
38
39
40
41
const dogs = [
// {name: 'Sammy'},
// {name: 'Roscoe'},
// {name: 'Pookie'},
// {name: 'Bailey'},
// {name: 'Butch'},
// {name: 'Sunshine'},
]
main();
async function main() {
await loadDogs();
displayDogs();
}
function displayDogs() {
for (let dog of dogs) {
addDogToDisplay(dog);
}
}
function addDogToDisplay(dog) {
const dogItem = document.createElement('a');
dogItem.href = '#';
dogItem.innerText = dog.name;
dogItem.className = 'list-group-item';
const dogsListUI = document.getElementById('dog-list');
dogsListUI.appendChild(dogItem);
}
async function loadDogs() {
const response = await fetch('/api/dogs');
const retrievedData = await response.json();
const retrievedDogs = retrievedData.dogs;
for (let dog of retrievedDogs) {
dogs.push(dog);
}
}