From d011e814693fb522f8bc99200fe2ee462b6f110d Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 22:43:14 +0000 Subject: [PATCH 01/31] Fix syntax error in render function loop --- 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 75ce6c1d3..eed706fdc 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 From 1e31fd1d8c66bab6b0ebe0a8515ce09c5602b4fe Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 22:46:10 +0000 Subject: [PATCH 02/31] Fix reference to myLibrary in submit function --- 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 eed706fdc..51a8c1cb6 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 40dfdc04e8817e066fc174d61a03360bfc4d5094 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 22:48:36 +0000 Subject: [PATCH 03/31] Fix author reference in book submission --- 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 51a8c1cb6..45277227e 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 3b6ff4664dbc245181b69beeb846e2fe2675833a Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 22:53:43 +0000 Subject: [PATCH 04/31] Fix variable name for delete button in render function --- 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 45277227e..19b79b96e 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -89,8 +89,7 @@ function render() { }); //add delete button to every row and render again - let delButton = document.createElement("button"); - delBut.id = i + 5; + let delBut = document.createElement("button"); deleteCell.appendChild(delBut); delBut.className = "btn btn-warning"; delBut.innerHTML = "Delete"; From fe52491e88f05614ba30ed76a1a121269e36c2f4 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 22:58:29 +0000 Subject: [PATCH 05/31] Fix read status condition in render function --- 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 19b79b96e..4ce6bd1db 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -76,7 +76,7 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == false) { + if (myLibrary[i].check) { readStatus = "Yes"; } else { readStatus = "No"; From cb6f8859e7e289589f1fe2c2a207cfa847d84fb6 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 23:00:05 +0000 Subject: [PATCH 06/31] Fix validation check for author field in submit function --- 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 4ce6bd1db..7d81e518d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -30,7 +30,7 @@ const check = document.getElementById("check"); function submit() { if ( title.value == null || - title.value == "" || + author.value == "" || pages.value == null || pages.value == "" ) { From 170437cebc7ba6e2a22e023d1d5868cb87134355 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 23:01:05 +0000 Subject: [PATCH 07/31] Simplify validation check in submit function --- debugging/book-library/script.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 7d81e518d..308fc89cb 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -28,12 +28,7 @@ const check = document.getElementById("check"); //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 || - author.value == "" || - pages.value == null || - pages.value == "" - ) { + if (title.value == "" || author.value == "" || pages.value == "") { alert("Please fill all fields!"); return false; } else { From 4d5e044b6161e83371ece2a2fce65a5c8a48df9b Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 23:04:13 +0000 Subject: [PATCH 08/31] Fix row insertion position in render function --- 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 308fc89cb..430e4c5b4 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -55,7 +55,7 @@ function render() { //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); From 9a98566970fabe688640aaa1d9e4436eba79d956 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 23:07:17 +0000 Subject: [PATCH 09/31] Reset form fields after adding a new book --- debugging/book-library/script.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 430e4c5b4..d2e01b801 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -35,6 +35,10 @@ function submit() { let book = new Book(title.value, author.value, pages.value, check.checked); myLibrary.push(book); render(); + title.value = ""; + author.value = ""; + pages.value = ""; + check.checked = false; } } From 632b8e6a03dfe18adfb31ca6a2fd5436f6374541 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 23:09:21 +0000 Subject: [PATCH 10/31] Fix label input types for author and title --- debugging/book-library/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71e..a8db7c309 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,4 +1,4 @@ - + @@ -31,7 +31,7 @@

Library

Library /> Library type="submit" value="Submit" class="btn btn-primary" - onclick="submit();" + onclick="submit()" />
From 1d4095f7af0c57991f0f1fc2f7e93752ee831349 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 23:12:25 +0000 Subject: [PATCH 11/31] Set the title for the Book Library page --- 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 a8db7c309..d7a143f17 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,7 +1,7 @@ - + Book Library Date: Wed, 25 Nov 2026 23:15:28 +0000 Subject: [PATCH 12/31] Remove redundant render call on window load --- 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 d2e01b801..19f623b44 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -2,7 +2,6 @@ let myLibrary = []; window.addEventListener("load", function (e) { populateStorage(); - render(); }); function populateStorage() { From 5e9a93f383c715cf056b7fd2a2204c5793b6766b Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 23:18:44 +0000 Subject: [PATCH 13/31] Fix event listener typo for delete button in render function --- 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 19f623b44..8eca52f41 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -91,7 +91,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 961177cc76a925de9aa422e8b08ad99d667976ca Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Wed, 25 Nov 2026 23:19:34 +0000 Subject: [PATCH 14/31] Fix typo in book title for initial library population --- 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 8eca52f41..dacfd869a 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -6,7 +6,7 @@ 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("Robinson Crusoe", "Daniel Defoe", "252", true); let book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", From 105cdc16ce92d86667cc076877ae98b44dbe097d Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 22:46:29 +0000 Subject: [PATCH 15/31] Refactor HTML structure --- debugging/book-library/index.html | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index d7a143f17..6d331aa4e 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,12 +1,10 @@ - + + + Book Library - + From cfc90faa0a7cb33101b0a9c71cae24dd136468d4 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 22:54:04 +0000 Subject: [PATCH 16/31] Add button type and update table headers for better accessibility --- debugging/book-library/index.html | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 6d331aa4e..d345ec28d 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -21,7 +21,12 @@

Library

Add books to your virtual library

- @@ -80,11 +85,11 @@

Library

- - - - - + + Author + Number of Pages + Read + Actions From 8bc04abb0f0b3c31e2da8c2ae608edd66ccbb89b Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 22:55:24 +0000 Subject: [PATCH 17/31] Fix tbody tag closure in book list table --- 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 d345ec28d..1c6f765d9 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -91,7 +91,7 @@

Library

Read Actions - + From 4f18c9306e13df8f9c1cd154002a1f4bbe15b55e Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 22:56:12 +0000 Subject: [PATCH 18/31] Add type="module" to script tag for ES module support --- 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 1c6f765d9..7d817451a 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -94,6 +94,6 @@

Library

- + From 5c15f3b9b292fddaa294a2d9357fd499e9c6955c Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 23:02:52 +0000 Subject: [PATCH 19/31] Fix form structure in book addition section --- debugging/book-library/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 7d817451a..9fbaae941 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -31,7 +31,7 @@

Library

-
+
Library class="btn btn-primary" onclick="submit()" /> -
+
From cd820c26b0decd305fa753b78a4bf25846b20500 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 23:05:44 +0000 Subject: [PATCH 20/31] Add checkbox and label for better accessibility in book form --- debugging/book-library/index.html | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 9fbaae941..84881fca5 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -56,20 +56,11 @@

Library

name="pages" required /> - - + +
+ + +
From c78996c5aede6166be05313db296a5757c9d9d3b Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 23:07:26 +0000 Subject: [PATCH 21/31] Add button for book form --- debugging/book-library/index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 84881fca5..96943cef1 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -61,6 +61,8 @@

Library

+ + From 357c49b51c3224b180cb196cfd8d6f4cc27973e6 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 23:14:22 +0000 Subject: [PATCH 22/31] Add message alert for form submission feedback --- 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 96943cef1..6fba1aef8 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -65,7 +65,7 @@

Library

- +
From 920ee863a929a80e5e57b91b08ce38cda10f355e Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 23:24:56 +0000 Subject: [PATCH 23/31] Refactor variable declarations for book form inputs --- debugging/book-library/script.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index dacfd869a..e9dcaa476 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,3 +1,11 @@ +const titleInput = document.getElementById("title"); +const authorInput = document.getElementById("author"); +const pagesInput = document.getElementById("pages"); +const readCheckbox = document.getElementById("check"); +const bookFormE1 = document.getElementById("book-form"); +const bookListE1 = document.getElementById("book-list"); +const messageE1 = document.getElementById("message"); + let myLibrary = []; window.addEventListener("load", function (e) { @@ -19,11 +27,6 @@ function populateStorage() { } } -const title = document.getElementById("title"); -const author = document.getElementById("author"); -const pages = document.getElementById("pages"); -const check = document.getElementById("check"); - //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 e04457b51822eaf2671c2d4c54704635ebc5f489 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 23:28:27 +0000 Subject: [PATCH 24/31] Move Book constructor function to the top --- debugging/book-library/script.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index e9dcaa476..07f8fb0c8 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -6,6 +6,13 @@ const bookFormE1 = document.getElementById("book-form"); const bookListE1 = document.getElementById("book-list"); const messageE1 = document.getElementById("message"); +function Book(title, author, pages, check) { + this.title = title; + this.author = author; + this.pages = pages; + this.check = check; +} + let myLibrary = []; window.addEventListener("load", function (e) { @@ -44,13 +51,6 @@ function submit() { } } -function Book(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; From 992d5538678f25a46a62f58c3ec4b13516956d0c Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 23:31:35 +0000 Subject: [PATCH 25/31] Remove unnecessary storage population logic and initialize myLibrary --- debugging/book-library/script.js | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 07f8fb0c8..fdb8c49e5 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -13,26 +13,10 @@ function Book(title, author, pages, check) { this.check = check; } -let myLibrary = []; - -window.addEventListener("load", function (e) { - populateStorage(); -}); - -function populateStorage() { - if (myLibrary.length == 0) { - 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(); - } -} +const myLibrary = [ + new Book("Robinson Crusoe", "Daniel Defoe", "252", true), + new Book("The Old Man and the Sea", "Ernest Hemingway", "127", true), +]; //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 e743a26455b53e9023b52d21df48b41ccde19295 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 23:34:11 +0000 Subject: [PATCH 26/31] Add showMessage function for form submission feedback --- debugging/book-library/script.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index fdb8c49e5..474c80fbe 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -18,6 +18,18 @@ const myLibrary = [ new Book("The Old Man and the Sea", "Ernest Hemingway", "127", true), ]; +let messageTimeoutId; + +function showMessage(text) { + messageE1.textContent = text; + messageE1.hidden = false; + + clearTimeout(messageTimeoutId); + messageTimeoutId = setTimeout(() => { + messageE1.hidden = true; + }, 3000); +} + //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 cf20104fc9a784872ba4a8375d63069d94f370a7 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 23:47:38 +0000 Subject: [PATCH 27/31] Refactor render function --- debugging/book-library/script.js | 66 ++++++++++++-------------------- 1 file changed, 25 insertions(+), 41 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 474c80fbe..763976b38 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -48,52 +48,36 @@ function submit() { } 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; + bookListE1.replaceChildren(); + + myLibrary.forEach((book, index) => { + const rowE1 = bookListE1.insertRow(); + rowE1.insertCell().textContent = book.title; + rowE1.insertCell().textContent = book.author; + rowE1.insertCell().textContent = book.pages; - //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 = ""; - if (myLibrary[i].check) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } - changeBut.innerText = readStatus; + const readCell = rowE1.insertCell(); + const deleteCell = rowE1.insertCell(); - changeBut.addEventListener("click", function () { - myLibrary[i].check = !myLibrary[i].check; + const readBtn = document.createElement("button"); + readBtn.type = "button"; + readBtn.className = "btn btn-success"; + readBtn.textContent = book.check ? "Yes" : "No"; + readBtn.addEventListener("click", () => { + book.check = !book.check; render(); }); + readCell.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); + const deleteBtn = document.createElement("button"); + deleteBtn.type = "button"; + deleteBtn.className = "btn btn-warning"; + deleteBtn.textContent = "Delete"; + deleteBtn.addEventListener("click", () => { + myLibrary.splice(index, 1); render(); + showMessage(`You've deleted title: ${book.title}`); }); - } + deleteCell.appendChild(deleteBtn); + }); } From 2dd05325b79ab48cb9a0aa5a99cfbb51eddd93d4 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 23:54:44 +0000 Subject: [PATCH 28/31] Refactor book submission logic --- debugging/book-library/script.js | 36 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 763976b38..9a550b883 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -30,23 +30,6 @@ function showMessage(text) { }, 3000); } -//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 == "" || author.value == "" || 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); - render(); - title.value = ""; - author.value = ""; - pages.value = ""; - check.checked = false; - } -} - function render() { bookListE1.replaceChildren(); @@ -81,3 +64,22 @@ function render() { deleteCell.appendChild(deleteBtn); }); } + +bookFormE1.addEventListener("submit", (event) => { + event.preventDefault(); + + const title = titleInput.value.trim(); + const author = authorInput.value.trim(); + const pages = Number(pagesInput.value); + + if(title === "" || author === "" || !Number.isInteger(pages) || pages < 1){ + alert("Please fill all fields with valid values!"); + return; + } + + myLibrary.push(new Book(title, author, pages, readCheckbox.checked)); + render(); + bookFormE1.reset(); +}); + +render(); From 58371116bcf831fe27849c1ffaccb352db53a6da Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sat, 28 Nov 2026 23:57:12 +0000 Subject: [PATCH 29/31] Remove redundant table row in book list display --- debugging/book-library/index.html | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 6fba1aef8..fdeae9ab6 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -76,15 +76,7 @@

Library

- - - - - - - - - +
AuthorNumber of PagesReadActions
From 6c91d7dc2dcabb8e2d41140b74c7ddf6c2fd8da4 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sun, 29 Nov 2026 00:03:32 +0000 Subject: [PATCH 30/31] Remove unused CSS properties and clean up form-check styles --- debugging/book-library/style.css | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/debugging/book-library/style.css b/debugging/book-library/style.css index 302950cb8..17650f464 100644 --- a/debugging/book-library/style.css +++ b/debugging/book-library/style.css @@ -1,7 +1,6 @@ .form-group { width: 400px; height: 300px; - align-self: left; padding-left: 20px; } @@ -9,11 +8,14 @@ display: block; } -.form-check-label { - padding-left: 20px; - margin: 5px 0px 5px 0px; +.form-check { + margin: 5px 0px 10px 0px; } button.btn-info { margin: 20px; } + +#message { + margin: 0 20px 20px 20px; +} From 20ff14b47310a9dc6f9053471f3bf518afc52b23 Mon Sep 17 00:00:00 2001 From: Precious Moses Date: Sun, 29 Nov 2026 00:19:48 +0000 Subject: [PATCH 31/31] Add confirmation message when a book is added --- debugging/book-library/script.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 9a550b883..24aa47477 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -72,13 +72,14 @@ bookFormE1.addEventListener("submit", (event) => { const author = authorInput.value.trim(); const pages = Number(pagesInput.value); - if(title === "" || author === "" || !Number.isInteger(pages) || pages < 1){ + if (title === "" || author === "" || !Number.isInteger(pages) || pages < 1) { alert("Please fill all fields with valid values!"); return; } myLibrary.push(new Book(title, author, pages, readCheckbox.checked)); render(); + showMessage(`You've added title: ${title}`); bookFormE1.reset(); });