Let’s extend the Book example from the previous lesson and turn it into a small Library app.
If you haven’t already, set up your project with skeleton HTML/CSS and JS files.
All of your book objects are going to be stored in a simple array, so add a function to the script (not the constructor) that can take user’s input and store the new book objects into an array. Your code should look something like this:
let myLibrary = [];
function Book() {
// the constructor...
}
function addBookToLibrary() {
// do stuff here
}
Hook the array up to your HTML with a render()
function that loops through the array and displays each book on the page. You can display them in some sort of table, or each on their own "card". It might help for now to manually add a few books to your array so you can see the display.
Add a "NEW BOOK" button that brings up a form allowing users to input the details for the new book: author, title, number of pages, whether it’s been read and anything else you might want.
Add a button on each book’s display to remove the book from the library.
Add a button on each book’s display to change its read
status.
read
status on your Book
prototype instance.Optional -we haven’t learned any techniques for actually storing our data anywhere, so when the user refreshes the page all of their books will disappear! If you want, you are capable of adding some persistence to this library app using one of the following techniques:
Read the instructions in the Exercises GitHub repository, create a new branch for this exercise, create a Pull Request and submit its URL in the Quiz below.
UPDATED: 27.12.2020