Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion book-library/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1>Library</h1>
<p>Add books to your virtual library</p>
</div>

<button data-toggle="collapse" data-target="#demo" class="btn btn-info">
<button type="button" data-toggle="collapse" data-target="#demo" class="btn btn-info">
Add new book
</button>

Expand Down
28 changes: 10 additions & 18 deletions book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ window.addEventListener("load", function (e) {
function populateStorage() {
if (myLibrary.length == 0) {
let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true);
let book2 = new Book(
"The Old Man and the Sea",
"Ernest Hemingway",
"127",
true
);
let book2 = new Book("The Old Man and the Sea", "Ernest Hemingway", "127", true);
myLibrary.push(book1);
myLibrary.push(book2);
render();
Expand All @@ -37,8 +32,8 @@ function submit() {
alert("Please fill all fields!");
return false;
} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
let book = new Book(title.value, author.value, pages.value, check.checked);
myLibrary.push(book);
render();
}
}
Expand All @@ -54,9 +49,10 @@ function render() {
let table = document.getElementById("display");
let rowsNumber = table.rows.length;
//delete old table
for (let n = rowsNumber - 1; n > 0; n-- {
for (let n = rowsNumber - 1; n > 0; n--){
table.deleteRow(n);
}
};

//insert updated row and cells
let length = myLibrary.length;
for (let i = 0; i < length; i++) {
Expand All @@ -69,18 +65,14 @@ function render() {
cell1.innerHTML = myLibrary[i].title;
cell2.innerHTML = myLibrary[i].author;
cell3.innerHTML = myLibrary[i].pages;


//add and wait for action for read/unread button
let changeBut = document.createElement("button");
changeBut.id = i;
changeBut.className = "btn btn-success";
cell4.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
readStatus = "Yes";
} else {
readStatus = "No";
}
let readStatus = myLibrary[i].check ? "Yes" : "No";
changeBut.innerHTML = readStatus;

changeBut.addEventListener("click", function () {
Expand All @@ -89,12 +81,12 @@ function render() {
});

//add delete button to every row and render again
let delButton = document.createElement("button");
let delBut = document.createElement("button");
delBut.id = i + 5;
cell5.appendChild(delBut);
delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
delBut.addEventListener("click", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
Expand Down