From cb859a17e7d23c91536d7fdcc85a2e924942d278 Mon Sep 17 00:00:00 2001 From: HilolaRustamova Date: Sat, 16 Aug 2025 14:47:44 +0100 Subject: [PATCH 1/3] fixed some syntax mistakes --- debugging/book-library/script.js | 37 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..a2d1d87d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -7,13 +7,8 @@ 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 book1 = new Book("Robinson Crusoe", "Daniel Defoe", "252", true); + let book2 = new Book("The Old Man and the Sea", "Ernest Hemingway", "127", true); myLibrary.push(book1); myLibrary.push(book2); render(); @@ -31,36 +26,40 @@ function submit() { if ( title.value == null || title.value == "" || + author.value == null || + author.value == "" || pages.value == null || pages.value == "" ) { 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(); } } -function Book(title, author, pages, check) { - this.title = title; - this.author = author; - this.pages = pages; - this.check = check; +class Book { + constructor(title, author, pages, check) { + this.title = title; + this.author = author; + this.pages = pages; + this.check = check; + } } 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++) { - let row = table.insertRow(1); + let row = table.insertRow(-1); let titleCell = row.insertCell(0); let authorCell = row.insertCell(1); let pagesCell = row.insertCell(2); @@ -76,7 +75,7 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == false) { + if (myLibrary[i].check == true) { readStatus = "Yes"; } else { readStatus = "No"; @@ -89,12 +88,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; deleteCell.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(); From b6e236f57f1cff2c0f31498e99103c3c639082de Mon Sep 17 00:00:00 2001 From: HilolaRustamova Date: Sat, 16 Aug 2025 19:44:55 +0100 Subject: [PATCH 2/3] fixed some problems on HTML --- debugging/book-library/index.html | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..7cb10f4a 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,12 +1,9 @@ - - + ModuleDataFlaw.BookLibrary + + @@ -31,7 +28,7 @@

Library

Library /> Library type="submit" value="Submit" class="btn btn-primary" - onclick="submit();" + onclick="submit(event);" />
@@ -81,13 +78,7 @@

Library

- - - - - - - + From b8b977b31ecac06fa0f6cb316adbb1f203e15f14 Mon Sep 17 00:00:00 2001 From: HilolaRustamova Date: Sat, 16 Aug 2025 19:45:18 +0100 Subject: [PATCH 3/3] fixed the bugs --- debugging/book-library/script.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index a2d1d87d..d1f79241 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,10 +1,13 @@ let myLibrary = []; window.addEventListener("load", function (e) { - populateStorage(); +if (localStorage.getItem("myLibrary")) { + myLibrary = JSON.parse(localStorage.getItem("myLibrary")); + } else { + populateStorage(); + } render(); }); - function populateStorage() { if (myLibrary.length == 0) { let book1 = new Book("Robinson Crusoe", "Daniel Defoe", "252", true);