From a1682cb980487a679b3695ffaffb39ee9fec4b4a Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Sun, 12 Apr 2026 09:42:48 +0200 Subject: [PATCH 01/22] Fix: allow books to display by correcting syntax errors --- debugging/book-library/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..abcd4293 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -54,7 +54,7 @@ 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 @@ -89,7 +89,7 @@ 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"; From e75af8779eba9bfed4bd47cb002023017b4b6cc4 Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Sun, 12 Apr 2026 09:50:55 +0200 Subject: [PATCH 02/22] Fix: allow new books to be added --- debugging/book-library/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index abcd4293..19c53ac2 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -38,7 +38,7 @@ function submit() { return false; } else { let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); + myLibrary.push(book); render(); } } From 3fd4d7a481320a370ba043d9ad6ddb96bece3394 Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Sun, 12 Apr 2026 09:53:17 +0200 Subject: [PATCH 03/22] Fix: display correct author name, and not title --- debugging/book-library/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 19c53ac2..f95d0887 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -37,7 +37,7 @@ function submit() { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, title.value, pages.value, check.checked); + let book = new Book(title.value, author.value, pages.value, check.checked); myLibrary.push(book); render(); } From 52b0d0bd120dea575a4a34a804deb61cbb1c99ed Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Sun, 12 Apr 2026 12:35:41 +0200 Subject: [PATCH 04/22] Fix: allow books to be deleted by correcting syntax error --- debugging/book-library/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index f95d0887..78525521 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -94,7 +94,7 @@ function render() { 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 d751fcc65632cebad3cd0c0e0dca565de6ef36e7 Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Sun, 12 Apr 2026 12:56:50 +0200 Subject: [PATCH 05/22] Fix: save checked status correctly --- debugging/book-library/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 78525521..dd143816 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -37,7 +37,7 @@ function submit() { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, author.value, pages.value, check.checked); + let book = new Book(title.value, author.value, pages.value, check.value); myLibrary.push(book); render(); } From 687952b9b9a83e45cb5d08000ee3f2e6aa7ddf8c Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Sun, 19 Apr 2026 14:08:44 +0200 Subject: [PATCH 06/22] Fix: correct syntax errors in HTML --- debugging/book-library/index.html | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..01efa284 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,12 +1,9 @@ - - + + - - + Virtual Book Library + + @@ -31,7 +28,7 @@

Library

Library /> Library type="submit" value="Submit" class="btn btn-primary" - onclick="submit();" + onclick="submit()" />
From f75c49badaebc8fb994ac98b1fbf3d11737f5d5c Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Sun, 19 Apr 2026 14:27:51 +0200 Subject: [PATCH 07/22] Modularize and isolate script.js --- debugging/book-library/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 01efa284..5803271b 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -88,6 +88,6 @@

Library

- + From 92f9595c755f36b89738dfcee25971d8e4bfda44 Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Sun, 19 Apr 2026 14:40:41 +0200 Subject: [PATCH 08/22] Fix: add event listener for submitting new book --- debugging/book-library/index.html | 2 +- debugging/book-library/script.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 5803271b..b2df478c 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -62,7 +62,7 @@

Library

type="submit" value="Submit" class="btn btn-primary" - onclick="submit()" + id="submitBtn" /> diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index dd143816..a47b6480 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -25,6 +25,9 @@ const author = document.getElementById("author"); const pages = document.getElementById("pages"); const check = document.getElementById("check"); +const submitBtn = document.querySelector('input[type="submit"]'); +submitBtn.addEventListener("click", submit); + //check the right input from forms and if its ok -> add the new book (object in array) //via Book function and start render function function submit() { From ea811f6d7d22a5054d3c8a98f53512b00ffd76b6 Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Sun, 19 Apr 2026 14:44:02 +0200 Subject: [PATCH 09/22] Style: clear the form after a new book is added --- debugging/book-library/script.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index a47b6480..933b8880 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -42,6 +42,12 @@ function submit() { } else { let book = new Book(title.value, author.value, pages.value, check.value); myLibrary.push(book); + + title.value = ""; + author.value = ""; + pages.value = ""; + check.value = false; + render(); } } From 58a38fa6807d1498aa452a85fd44a9f17f79d931 Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Sun, 19 Apr 2026 14:54:50 +0200 Subject: [PATCH 10/22] Fix: correct read label status --- debugging/book-library/index.html | 7 +------ debugging/book-library/script.js | 6 +++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index b2df478c..f9505532 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -51,12 +51,7 @@

Library

required /> Date: Mon, 20 Apr 2026 03:19:09 +0200 Subject: [PATCH 11/22] Validate input before form is submitted --- debugging/book-library/index.html | 80 +++++++++++++++++-------------- debugging/book-library/script.js | 6 ++- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index f9505532..7a8def65 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -25,41 +25,51 @@

Library

-
- - - - - - - - -
+
+
+ + + + + + + + +
+
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 59361a37..ef332102 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -25,8 +25,10 @@ const author = document.getElementById("author"); const pages = document.getElementById("pages"); const check = document.getElementById("check"); -const submitBtn = document.querySelector('input[type="submit"]'); -submitBtn.addEventListener("click", submit); +const submitForm = document.getElementById("bookForm"); +submitForm.addEventListener("submit", function (e) { + e.preventDefault(); +}); //check the right input from forms and if its ok -> add the new book (object in array) //via Book function and start render function From 672ec4e89dc77867c49f7e0daf2e602bc0b0ca20 Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Mon, 20 Apr 2026 03:29:40 +0200 Subject: [PATCH 12/22] Fix: correctly add new books into library --- debugging/book-library/script.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index ef332102..7fabc270 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -28,6 +28,12 @@ const check = document.getElementById("check"); const submitForm = document.getElementById("bookForm"); submitForm.addEventListener("submit", function (e) { e.preventDefault(); + + let book = new Book(title.value, author.value, pages.value, check.checked); + myLibrary.push(book); + submitForm.reset(); + + render(); }); //check the right input from forms and if its ok -> add the new book (object in array) From bad4502fe185447188862e2c6ecd02e68e110ae4 Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Mon, 20 Apr 2026 03:31:41 +0200 Subject: [PATCH 13/22] Refactor: remove duplicate rendering --- debugging/book-library/script.js | 1 - 1 file changed, 1 deletion(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 7fabc270..088c2b6e 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -16,7 +16,6 @@ function populateStorage() { ); myLibrary.push(book1); myLibrary.push(book2); - render(); } } From c4cd9b4d112902cef545f58abadd99928576092c Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Mon, 20 Apr 2026 03:36:02 +0200 Subject: [PATCH 14/22] Refactor: remove duplicate forms input validation --- debugging/book-library/script.js | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 088c2b6e..1f6d175d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -35,30 +35,6 @@ submitForm.addEventListener("submit", function (e) { render(); }); -//check the right input from forms and if its ok -> add the new book (object in array) -//via Book function and start render function -function submit() { - if ( - title.value == null || - title.value == "" || - pages.value == null || - pages.value == "" - ) { - alert("Please fill all fields!"); - return false; - } else { - let book = new Book(title.value, author.value, pages.value, check.checked); - myLibrary.push(book); - - title.value = ""; - author.value = ""; - pages.value = ""; - check.checked = false; - - render(); - } -} - function Book(title, author, pages, check) { this.title = title; this.author = author; From 1b9ec8ea6b9b81421ed0c267e8b1b085ab4fd633 Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Mon, 20 Apr 2026 03:41:54 +0200 Subject: [PATCH 15/22] Refactor: remove unneccessary id labelling --- debugging/book-library/script.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 1f6d175d..c9a8e086 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -64,7 +64,6 @@ function render() { //add and wait for action for read/unread button let changeBut = document.createElement("button"); - changeBut.id = i; changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; @@ -82,7 +81,6 @@ function render() { //add delete button to every row and render again let delBut = document.createElement("button"); - delBut.id = i + 5; deleteCell.appendChild(delBut); delBut.className = "btn btn-warning"; delBut.innerHTML = "Delete"; From 5f43e963d2191ca6f1fd3beaa4224298d93269f8 Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Mon, 20 Apr 2026 03:58:59 +0200 Subject: [PATCH 16/22] Refactor: simplify repetitive code --- debugging/book-library/script.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index c9a8e086..f9f10833 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -14,8 +14,7 @@ function populateStorage() { "127", true ); - myLibrary.push(book1); - myLibrary.push(book2); + myLibrary.push(book1, book2); } } From b8786ad3f0ee57ed5480ece49e1d50ab10ef160c Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Mon, 20 Apr 2026 04:16:42 +0200 Subject: [PATCH 17/22] Refactor: simplify render function --- debugging/book-library/script.js | 70 ++++++++++++++------------------ 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index f9f10833..b175a3d6 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -42,51 +42,41 @@ function Book(title, author, pages, check) { } function render() { - let table = document.getElementById("display"); - let rowsNumber = table.rows.length; - //delete old table - 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 titleCell = row.insertCell(0); - let authorCell = row.insertCell(1); - let pagesCell = row.insertCell(2); - let wasReadCell = row.insertCell(3); - let deleteCell = row.insertCell(4); - titleCell.innerHTML = myLibrary[i].title; - authorCell.innerHTML = myLibrary[i].author; - pagesCell.innerHTML = myLibrary[i].pages; + const tbody = document.querySelector("#display tbody"); + // Clear existing rows + tbody.innerHTML = ""; + + myLibrary.forEach((book, index) => { + // Create a new row and cells for each book + const row = tbody.insertRow(); + row.insertCell(0).textContent = book.title; + row.insertCell(1).textContent = book.author; + row.insertCell(2).textContent = book.pages; - //add and wait for action for read/unread button - let changeBut = document.createElement("button"); - changeBut.className = "btn btn-success"; - wasReadCell.appendChild(changeBut); - let readStatus = ""; - if (myLibrary[i].check == true) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } - changeBut.innerText = readStatus; + const wasReadCell = row.insertCell(3); + const readBtn = document.createElement("button"); + readBtn.className = "btn btn-success"; + readBtn.textContent = book.check ? "Yes" : "No"; - changeBut.addEventListener("click", function () { - myLibrary[i].check = !myLibrary[i].check; + // Toggle the read status when the button is clicked + readBtn.addEventListener("click", () => { + book.check = !book.check; render(); }); + wasReadCell.appendChild(readBtn); - //add delete button to every row and render again - let delBut = document.createElement("button"); - deleteCell.appendChild(delBut); - delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; - delBut.addEventListener("click", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); - myLibrary.splice(i, 1); + // Create a delete button for each book + const deleteCell = row.insertCell(4); + const deleteBtn = document.createElement("button"); + deleteBtn.className = "btn btn-warning"; + deleteBtn.textContent = "Delete"; + + // Render the updated library when the delete button is clicked + deleteBtn.addEventListener("click", () => { + alert(`You've deleted title: ${book.title}`); + myLibrary.splice(index, 1); render(); }); - } + deleteCell.appendChild(deleteBtn); + }); } From 0e8dec08d9471a766da46be71a307a1fb3ca57db Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Mon, 20 Apr 2026 04:22:53 +0200 Subject: [PATCH 18/22] Refactor: treat page count as an integer throughout --- debugging/book-library/script.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index b175a3d6..f415faf2 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -7,11 +7,11 @@ window.addEventListener("load", function (e) { function populateStorage() { if (myLibrary.length == 0) { - let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); + let book1 = new Book("Robison Crusoe", "Daniel Defoe", 252, true); let book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", - "127", + 127, true ); myLibrary.push(book1, book2); @@ -27,7 +27,12 @@ const submitForm = document.getElementById("bookForm"); submitForm.addEventListener("submit", function (e) { e.preventDefault(); - let book = new Book(title.value, author.value, pages.value, check.checked); + let book = new Book( + title.value, + author.value, + parseInt(pages.value), + check.checked + ); myLibrary.push(book); submitForm.reset(); From 5a768e1469af605d1b04239205b8396a27a1f6ab Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Mon, 20 Apr 2026 04:26:15 +0200 Subject: [PATCH 19/22] Refactor: improve readbility with more descriptive variable names --- debugging/book-library/script.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index f415faf2..0a18326a 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -18,20 +18,20 @@ function populateStorage() { } } -const title = document.getElementById("title"); -const author = document.getElementById("author"); -const pages = document.getElementById("pages"); -const check = document.getElementById("check"); +const titleInput = document.getElementById("title"); +const authorInput = document.getElementById("author"); +const pagesInput = document.getElementById("pages"); +const checkInput = document.getElementById("check"); const submitForm = document.getElementById("bookForm"); submitForm.addEventListener("submit", function (e) { e.preventDefault(); let book = new Book( - title.value, - author.value, - parseInt(pages.value), - check.checked + titleInput.value, + authorInput.value, + parseInt(pagesInput.value), + checkInput.checked ); myLibrary.push(book); submitForm.reset(); From b72bd52588ca3bfb14d754bc0670caa96c50621c Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Mon, 20 Apr 2026 04:33:26 +0200 Subject: [PATCH 20/22] Refactor: sanitize form input to remove uneccessary white spaces --- debugging/book-library/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 0a18326a..90662874 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -28,8 +28,8 @@ submitForm.addEventListener("submit", function (e) { e.preventDefault(); let book = new Book( - titleInput.value, - authorInput.value, + titleInput.value.trim(), + authorInput.value.trim(), parseInt(pagesInput.value), checkInput.checked ); From 2b390dce18d894f38874367e326b3db9f0122521 Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Mon, 20 Apr 2026 07:32:57 +0200 Subject: [PATCH 21/22] Refactor: display alert message only after successful deletion --- debugging/book-library/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 90662874..bc42d94e 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -78,8 +78,8 @@ function render() { // Render the updated library when the delete button is clicked deleteBtn.addEventListener("click", () => { - alert(`You've deleted title: ${book.title}`); myLibrary.splice(index, 1); + alert(`You've deleted title: ${book.title}`); render(); }); deleteCell.appendChild(deleteBtn); From 314fb76e5081d0a0c1caf13ab631e051ebe53983 Mon Sep 17 00:00:00 2001 From: Isaac Abodunrin Date: Mon, 20 Apr 2026 07:41:10 +0200 Subject: [PATCH 22/22] Refactor: declare myLibrary with const instead of let --- debugging/book-library/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index bc42d94e..12b61272 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,4 +1,4 @@ -let myLibrary = []; +const myLibrary = []; window.addEventListener("load", function (e) { populateStorage();