From 545a578af006cb891d5b7cfcac07a0347dfd6660 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Mon, 13 Apr 2026 08:26:43 +0100 Subject: [PATCH 01/15] Add a bracket in line 57 after n-- to enable the render function free of 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 75ce6c1d..eed706fd 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 d7e918d5534344903400b00b4444177b2a682b30 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Mon, 13 Apr 2026 08:34:03 +0100 Subject: [PATCH 02/15] Effect new change on line 47 to replace library.push with myLibrary.push --- 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 eed706fd..51a8c1cb 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 a0563ad6f531b8d8f7bac45f7dd46bf39a5df4cf Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Mon, 13 Apr 2026 08:40:56 +0100 Subject: [PATCH 03/15] Change the html onclick submit to addbook and implement the function function addbook too. --- debugging/book-library/index.html | 2 +- debugging/book-library/script.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..bb392dfc 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -65,7 +65,7 @@

Library

type="submit" value="Submit" class="btn btn-primary" - onclick="submit();" + onclick="addBook();" /> diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 51a8c1cb..2bf29867 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -27,7 +27,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() { +function addBook() { if ( title.value == null || title.value == "" || From fcc41d92de474b0590a056d55dd807420b9d7496 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Mon, 13 Apr 2026 08:44:08 +0100 Subject: [PATCH 04/15] Replace one of the title.value to author.value. --- 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 2bf29867..c58ebc31 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -37,7 +37,7 @@ function addBook() { 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 f71d019ebfc8724217ae683de5e9cb4481673646 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Mon, 13 Apr 2026 08:51:43 +0100 Subject: [PATCH 05/15] Replace all delbut with delButton --- debugging/book-library/script.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index c58ebc31..0ef69d72 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -90,11 +90,11 @@ function render() { //add delete button to every row and render again let delButton = document.createElement("button"); - delBut.id = i + 5; + delButton.id = i + 5; deleteCell.appendChild(delBut); - delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delButton.className = "btn btn-warning"; + delButton.innerHTML = "Delete"; + delButton.addEventListener("clicks", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From aee0f7c847d4c79b6ad42c7ce77f4a57c236364c Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Mon, 13 Apr 2026 08:54:23 +0100 Subject: [PATCH 06/15] Replace line 79 with true. --- 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 0ef69d72..46098eeb 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 == true) { readStatus = "Yes"; } else { readStatus = "No"; From afb91d197672b102694017996ec2f581cd7baab0 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Mon, 13 Apr 2026 09:03:59 +0100 Subject: [PATCH 07/15] validate the author also. --- debugging/book-library/script.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 46098eeb..42d9140f 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -31,6 +31,8 @@ function addBook() { if ( title.value == null || title.value == "" || + author.value == null || + author.value == "" || pages.value == null || pages.value == "" ) { From b5023677dc0728859390a3ee15812910a81f2cf5 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Mon, 13 Apr 2026 16:07:20 +0100 Subject: [PATCH 08/15] Implement new change. --- 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 42d9140f..2d78b6c8 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -93,10 +93,10 @@ function render() { //add delete button to every row and render again let delButton = document.createElement("button"); delButton.id = i + 5; - deleteCell.appendChild(delBut); + deleteCell.appendChild(delButton); delButton.className = "btn btn-warning"; delButton.innerHTML = "Delete"; - delButton.addEventListener("clicks", function () { + delButton.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From c4f042635e306d19b4afd7a81731465c3b903781 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Mon, 13 Apr 2026 16:16:49 +0100 Subject: [PATCH 09/15] update changes. --- 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 2d78b6c8..9b23417c 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,10 +1,5 @@ let myLibrary = []; -window.addEventListener("load", function (e) { - populateStorage(); - render(); -}); - function populateStorage() { if (myLibrary.length == 0) { let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); @@ -39,7 +34,7 @@ function addBook() { 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, parseInt(pages.value), check.checked); myLibrary.push(book); render(); } From 50224a3f5b6990f96c53bf2380fd037fbc65a28b Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Mon, 13 Apr 2026 16:21:15 +0100 Subject: [PATCH 10/15] Remove the other render inside the function populateStorage. --- 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 9b23417c..cb2894f4 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,5 +1,8 @@ let myLibrary = []; - +window.addEventListener("load", function () { + populateStorage(); + render(); +}); function populateStorage() { if (myLibrary.length == 0) { let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); @@ -11,7 +14,7 @@ function populateStorage() { ); myLibrary.push(book1); myLibrary.push(book2); - render(); + } } From 86339e52f1e91938021c0cb495818ed8312d4e2e Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Mon, 13 Apr 2026 16:46:08 +0100 Subject: [PATCH 11/15] Remove the strings in numbers 252 and 127. --- 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 cb2894f4..392e757b 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -5,11 +5,11 @@ window.addEventListener("load", function () { }); 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); From 2cad40937b0a7a1c25541d55d5df11f964780b8f Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Thu, 16 Apr 2026 16:49:06 +0100 Subject: [PATCH 12/15] Update html, buy adding title name Library, improve meta tag, ensure html validation with required, pattern and min, also load script with type module. --- debugging/book-library/index.html | 40 ++++++++++++++----------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index bb392dfc..9278ca07 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,12 +1,9 @@ - - + Library + + @@ -31,19 +28,21 @@

Library

Library id="pages" name="pages" required + min="1" /> - + > + submit +
@@ -81,16 +83,10 @@

Library

- - - - - - - + - + From b8f4d080035297f08270d0fee0170b779a9e418f Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Thu, 16 Apr 2026 17:07:20 +0100 Subject: [PATCH 13/15] Update new script.js --- debugging/book-library/script.js | 144 ++++++++++++++++--------------- 1 file changed, 73 insertions(+), 71 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 392e757b..73aa0039 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,46 +1,48 @@ -let myLibrary = []; -window.addEventListener("load", function () { +const myLibrary = []; + +window.addEventListener("load", () => { populateStorage(); render(); }); + function populateStorage() { - if (myLibrary.length == 0) { - let book1 = new Book("Robison Crusoe", "Daniel Defoe", 252, true); - let book2 = new Book( + if (myLibrary.length === 0) { + const book1 = new Book("Robinson Crusoe", "Daniel Defoe", 252, true); + const book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", 127, true ); - myLibrary.push(book1); - myLibrary.push(book2); - + + myLibrary.push(book1, book2); } } -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"); -//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 addBook() { - 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, author.value, parseInt(pages.value), check.checked); - myLibrary.push(book); - render(); + const titleValue = titleInput.value.trim(); + const authorValue = authorInput.value.trim(); + const pagesValue = Number(pagesInput.value); + + if (!titleValue || !authorValue || pagesValue <= 0) { + alert("Please fill all fields correctly!"); + return; } + + const book = new Book( + titleValue, + authorValue, + pagesValue, + checkInput.checked + ); + myLibrary.push(book); + + render(); } function Book(title, author, pages, check) { @@ -51,53 +53,53 @@ 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; - - //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 == true) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } - changeBut.innerText = readStatus; - - changeBut.addEventListener("click", function () { - myLibrary[i].check = !myLibrary[i].check; + const table = document.getElementById("display"); + + table.innerHTML = ` + + Title + Author + Pages + Read + Delete + + `; + + myLibrary.forEach((book, i) => { + const row = table.insertRow(); + + const titleCell = row.insertCell(0); + const authorCell = row.insertCell(1); + const pagesCell = row.insertCell(2); + const wasReadCell = row.insertCell(3); + const deleteCell = row.insertCell(4); + + titleCell.textContent = book.title; + authorCell.textContent = book.author; + pagesCell.textContent = book.pages; + + const changeBtn = document.createElement("button"); + changeBtn.className = "btn btn-success"; + changeBtn.textContent = book.check ? "Yes" : "No"; + + changeBtn.addEventListener("click", () => { + book.check = !book.check; render(); }); - //add delete button to every row and render again - let delButton = document.createElement("button"); - delButton.id = i + 5; - deleteCell.appendChild(delButton); - delButton.className = "btn btn-warning"; - delButton.innerHTML = "Delete"; - delButton.addEventListener("click", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); + wasReadCell.appendChild(changeBtn); + + const deleteBtn = document.createElement("button"); + deleteBtn.className = "btn btn-warning"; + deleteBtn.textContent = "Delete"; + + deleteBtn.addEventListener("click", () => { myLibrary.splice(i, 1); render(); + alert(`You've deleted title: ${book.title}`); }); - } + + deleteCell.appendChild(deleteBtn); + }); } +window.addBook = addBook; From a55ce60257b27e2acc73615e3100f90605f172c3 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Thu, 16 Apr 2026 19:54:48 +0100 Subject: [PATCH 14/15] Updated the function to address NaN. --- 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 73aa0039..d3210cdd 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -29,7 +29,7 @@ function addBook() { const authorValue = authorInput.value.trim(); const pagesValue = Number(pagesInput.value); - if (!titleValue || !authorValue || pagesValue <= 0) { + if (!titleValue || !authorValue || Number.isNaN (pagesValue)<= 0) { alert("Please fill all fields correctly!"); return; } From 0fc4d1ee5e1ff00903c9bf5eaee9ec88838b8fc3 Mon Sep 17 00:00:00 2001 From: tasleemadedokun Date: Thu, 16 Apr 2026 20:26:30 +0100 Subject: [PATCH 15/15] update the new version of js. --- debugging/book-library/script.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index d3210cdd..cd04cd33 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -29,7 +29,12 @@ function addBook() { const authorValue = authorInput.value.trim(); const pagesValue = Number(pagesInput.value); - if (!titleValue || !authorValue || Number.isNaN (pagesValue)<= 0) { + if ( + !titleValue || + !authorValue || + Number.isNaN(pagesValue) || + pagesValue <= 0 + ) { alert("Please fill all fields correctly!"); return; } @@ -40,8 +45,8 @@ function addBook() { pagesValue, checkInput.checked ); - myLibrary.push(book); + myLibrary.push(book); render(); } @@ -53,20 +58,12 @@ function Book(title, author, pages, check) { } function render() { - const table = document.getElementById("display"); - - table.innerHTML = ` - - Title - Author - Pages - Read - Delete - - `; + const tbody = document.querySelector("#display tbody"); + + tbody.innerHTML = ""; myLibrary.forEach((book, i) => { - const row = table.insertRow(); + const row = tbody.insertRow(); const titleCell = row.insertCell(0); const authorCell = row.insertCell(1); @@ -102,4 +99,5 @@ function render() { deleteCell.appendChild(deleteBtn); }); } + window.addBook = addBook;