From eac59146196215c14d551cab4154e90e6d86d343 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 19:35:09 +0000 Subject: [PATCH 01/26] Fix syntax: missing closing brace --- 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 d09f10db0d09a1f88646ea3319418e6bf1e3b283 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 19:38:50 +0000 Subject: [PATCH 02/26] Fix: Render all books on page load and when adding new books using form --- 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 eed706fd..608a02ed 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(); } } @@ -89,12 +89,12 @@ function render() { }); //add delete button to every row and render again - let delButton = document.createElement("button"); - delBut.id = i + 5; - deleteCell.appendChild(delBut); - delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + let delBtn = document.createElement("button"); + delBtn.id = i + 5; + deleteCell.appendChild(delBtn); + delBtn.className = "btn btn-warning"; + delBtn.innerHTML = "Delete"; + delBtn.addEventListener("clicks", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From e5c86062069913da231154946b6a688b80826dd7 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 19:48:17 +0000 Subject: [PATCH 03/26] change let to const on initial books to prevent accidental reassignment --- debugging/book-library/script.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 608a02ed..5188b0a4 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -7,13 +7,14 @@ 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( + const book1 = new Book("Robison 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); render(); From fcb63beaa21dffc865ef8d7044b7fe7c60c54082 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 19:52:36 +0000 Subject: [PATCH 04/26] renamed check to completed for clarity --- 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 5188b0a4..12000d03 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -44,11 +44,11 @@ function submit() { } } -function Book(title, author, pages, check) { +function Book(title, author, pages, completed) { this.title = title; this.author = author; this.pages = pages; - this.check = check; + this.completed = completed; } function render() { From d5aef674751c4fde4bb0884931d24d66f82a5be7 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 20:01:59 +0000 Subject: [PATCH 05/26] changed to match naming in the javascript, and for clarity. --- 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 23acfa71..2bcf29ed 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,4 +1,4 @@ - + @@ -59,13 +59,13 @@

Library

class="form-check-input" id="check" value="" - />Read + />completed @@ -76,7 +76,7 @@

Library

Title Author Number of Pages - Read + Completed From 7825b0002b9a2277d4b4a6550c69f51a5d929ee5 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 20:09:01 +0000 Subject: [PATCH 06/26] Fix: Display correct completed status and change button --- 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 12000d03..47208dd1 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -77,7 +77,7 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == false) { + if (myLibrary[i].completed == true) { readStatus = "Yes"; } else { readStatus = "No"; @@ -85,7 +85,7 @@ function render() { changeBut.innerText = readStatus; changeBut.addEventListener("click", function () { - myLibrary[i].check = !myLibrary[i].check; + myLibrary[i].completed = !myLibrary[i].completed; render(); }); From 2ddbdb43b565bc6c1d96464286dcc8c7525347c3 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 21:08:16 +0000 Subject: [PATCH 07/26] fix delete button --- 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 47208dd1..1a8bb209 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -95,7 +95,7 @@ function render() { deleteCell.appendChild(delBtn); delBtn.className = "btn btn-warning"; delBtn.innerHTML = "Delete"; - delBtn.addEventListener("clicks", function () { + delBtn.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 4b9e8a130da65c242a6e95233538fbfe766026b5 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 21:12:38 +0000 Subject: [PATCH 08/26] remove unnecessary id on change button --- 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 1a8bb209..0754efcf 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -73,7 +73,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 = ""; From c933c4dae5ab4a10dbd1e25f4f2bc775e02ade15 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 21:57:15 +0000 Subject: [PATCH 09/26] remove unnecessary render in load --- 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 0754efcf..ac0a6e4e 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -2,7 +2,7 @@ let myLibrary = []; window.addEventListener("load", function (e) { populateStorage(); - render(); + // render(); }); function populateStorage() { From 9e475eca34c368bdace2e8b433957f1b38497084 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 21:58:23 +0000 Subject: [PATCH 10/26] remove unnecessary id in delete button --- 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 ac0a6e4e..adc944eb 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -90,7 +90,6 @@ function render() { //add delete button to every row and render again let delBtn = document.createElement("button"); - delBtn.id = i + 5; deleteCell.appendChild(delBtn); delBtn.className = "btn btn-warning"; delBtn.innerHTML = "Delete"; From 481c9d2cf40d27c2805207eac21b1b26ac01ddd6 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 22:08:49 +0000 Subject: [PATCH 11/26] reset input fields after adding new book --- debugging/book-library/script.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index adc944eb..8d682663 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -40,10 +40,18 @@ function submit() { } else { let book = new Book(title.value, title.value, pages.value, check.checked); myLibrary.push(book); + resetInputFields(); render(); } } +function resetInputFields() { + title.value = ""; + author.value = ""; + pages.value = ""; + check.checked = false; +} + function Book(title, author, pages, completed) { this.title = title; this.author = author; From 92aa7dd8ee3f93369300f06234781d06da03df42 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 22:28:40 +0000 Subject: [PATCH 12/26] prevent duplicate book entries Duplicate: title and author both the same as an existing book. Not case sensitive. --- debugging/book-library/script.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 8d682663..99c01938 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -37,12 +37,25 @@ function submit() { ) { alert("Please fill all fields!"); return false; - } else { - let book = new Book(title.value, title.value, pages.value, check.checked); - myLibrary.push(book); - resetInputFields(); - render(); } + + let book = new Book(title.value, author.value, pages.value, check.checked); + + if (isBookInLibrary(book)) { + alert("This book is already in the library!"); + return false; + } + myLibrary.push(book); + resetInputFields(); + render(); +} + +function isBookInLibrary(newBook) { + return myLibrary.some( + (old) => + old.title.toLowerCase() === newBook.title.toLowerCase() && + old.author.toLowerCase() === newBook.author.toLowerCase() + ); } function resetInputFields() { From 219e37e2a5442abf6614beff8ba10db4e3e488ae Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 6 Mar 2026 22:33:57 +0000 Subject: [PATCH 13/26] remove dead code --- 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 99c01938..71283f6b 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 e6f827fcc24c99b7948dc97f28c77cf52bbc7287 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 8 May 2026 15:08:06 +0100 Subject: [PATCH 14/26] rename completed btn for clarity --- debugging/book-library/script.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 71283f6b..bbea3b8c 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -92,18 +92,18 @@ function render() { pagesCell.innerHTML = myLibrary[i].pages; //add and wait for action for read/unread button - let changeBut = document.createElement("button"); - changeBut.className = "btn btn-success"; - wasReadCell.appendChild(changeBut); + let changeCompletedBtn = document.createElement("button"); + changeCompletedBtn.className = "btn btn-success"; + wasReadCell.appendChild(changeCompletedBtn); let readStatus = ""; if (myLibrary[i].completed == true) { readStatus = "Yes"; } else { readStatus = "No"; } - changeBut.innerText = readStatus; + changeCompletedBtn.innerText = readStatus; - changeBut.addEventListener("click", function () { + changeCompletedBtn.addEventListener("click", function () { myLibrary[i].completed = !myLibrary[i].completed; render(); }); From c1db8fbec20afecc09e74af5962d41948385be51 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Fri, 8 May 2026 15:24:19 +0100 Subject: [PATCH 15/26] change color of completed btn to reflect status --- debugging/book-library/script.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index bbea3b8c..48b7fd78 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -93,13 +93,17 @@ function render() { //add and wait for action for read/unread button let changeCompletedBtn = document.createElement("button"); - changeCompletedBtn.className = "btn btn-success"; + changeCompletedBtn.className = "btn"; wasReadCell.appendChild(changeCompletedBtn); let readStatus = ""; if (myLibrary[i].completed == true) { readStatus = "Yes"; + changeCompletedBtn.classList.add("btn-success"); + changeCompletedBtn.classList.remove("btn-secondary"); } else { readStatus = "No"; + changeCompletedBtn.classList.remove("btn-success"); + changeCompletedBtn.classList.add("btn-secondary"); } changeCompletedBtn.innerText = readStatus; From cb062e222a78735fc026807925fa43239d59dd23 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Thu, 14 May 2026 10:24:38 +0100 Subject: [PATCH 16/26] fix input name, id and type values --- debugging/book-library/index.html | 17 ++++++----------- debugging/book-library/script.js | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 2bcf29ed..31ad7801 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,12 +1,7 @@ - + - - + Book library app @@ -29,12 +24,12 @@

Library

- + diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 48b7fd78..b1ddcbd0 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -20,7 +20,7 @@ function populateStorage() { } } -const title = document.getElementById("title"); +const title = document.getElementById("book-title"); const author = document.getElementById("author"); const pages = document.getElementById("pages"); const check = document.getElementById("check"); From d1a2249fc6961ef1e98d9a36d26336d0b7076599 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Thu, 14 May 2026 10:25:25 +0100 Subject: [PATCH 17/26] fix author input type --- 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 31ad7801..ccb5298b 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -34,7 +34,7 @@

Library

/> Date: Thu, 14 May 2026 10:34:31 +0100 Subject: [PATCH 18/26] add script as a module --- debugging/book-library/index.html | 5 ++--- debugging/book-library/script.js | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index ccb5298b..0a6f48b6 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -10,6 +10,7 @@ href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" /> + @@ -60,7 +61,7 @@

Library

type="submit" value="Submit" class="btn btn-primary" - onclick="submit()" + id="submit-btn" />
@@ -85,7 +86,5 @@

Library

- - diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index b1ddcbd0..22cee955 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -24,6 +24,7 @@ const title = document.getElementById("book-title"); const author = document.getElementById("author"); const pages = document.getElementById("pages"); const check = document.getElementById("check"); +const submitBtn = document.getElementById("submit-btn"); //check the right input from forms and if its ok -> add the new book (object in array) //via Book function and start render function @@ -49,6 +50,8 @@ function submit() { render(); } +submitBtn.addEventListener("click", submit); + function isBookInLibrary(newBook) { return myLibrary.some( (old) => From fc959f48bbcf91a19cf069d59be98d76b8123fff Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Thu, 14 May 2026 10:37:23 +0100 Subject: [PATCH 19/26] input validation --- debugging/book-library/index.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 0a6f48b6..14b7fae0 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -10,7 +10,7 @@ href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" /> - + @@ -31,6 +31,8 @@

Library

class="form-control" id="book-title" name="book-title" + minlength="1" + maxlength="200" required /> @@ -39,6 +41,8 @@

Library

class="form-control" id="author" name="author" + minlength="2" + maxlength="100" required /> @@ -47,6 +51,8 @@

Library

class="form-control" id="pages" name="pages" + min="1" + max="10000" required />