forked from qa-apprenticeships/devops-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (29 loc) · 1.02 KB
/
index.js
File metadata and controls
31 lines (29 loc) · 1.02 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
function sortByName(items) {
items.sort(function(a, b){
if(a.name < b.name) { return -1; }
if(a.name > b.name) { return 1; }
return 0;
})
return items
}
function getBookElement(name, author, image) {
let newBookElement = document.createElement("DIV")
newBookElement.className = "book"
let imageElement = document.createElement("IMG")
imageElement.src = image
newBookElement.appendChild(imageElement)
let bookNameElement = document.createElement("H2")
bookNameElement.innerHTML = name
newBookElement.appendChild(bookNameElement)
let bookAuthorElement = document.createElement("P")
bookAuthorElement.innerHTML = "by " + author
newBookElement.appendChild(bookAuthorElement)
return newBookElement
}
axios.get("/api/books").then((response) => {
let books = sortByName(response.data)
let bookShelve = document.getElementById("bookshelve")
books.forEach(book => {
bookShelve.appendChild(getBookElement(book.Name, book.Author, book.Image))
});
})