let myLibrary = [ { author: "JK Rowling", title: "Harry Potter and the Philosopher's Stone", pages: 223, read: true, }, { author: "Suzanne Collins", title: "The Hunger Games", pages: 374, read: true, }, { author: " J. R. R. Tolkien", title: "The Hobbit", pages: 304, read: false, }, ]; function Book(author, title, pages, read) { this.author = author; this.title = title; this.pages = pages; this.read = read; } const onLoad = () => { books(); showForm(); }; function addBookToLibrary() { var author = document.getElementById("author").value; var title = document.getElementById("title").value; var pages = document.getElementById("pages").value; var read = document.getElementById("read").checked; if (author === "" || title === "") { alert("Author or Title should not be blank"); } else { myLibrary.push(new Book(author, title, pages, read)); books(); } document.getElementById("author").value = ""; document.getElementById("title").value = ""; document.getElementById("pages").value = ""; document.getElementById("read").checked = false; } const books = () => { var book_list = myLibrary .map((book, index) => { return `
${book.pages} pages
${book.read ? "Read" : "Not Read"}