From c65e2e087303ebfdc1688202b047371ba8aa6d91 Mon Sep 17 00:00:00 2001 From: JorvanW Date: Thu, 13 Aug 2026 15:03:11 +0100 Subject: [PATCH 01/17] made changes to the script.js to fix the issues with the library site and made sure it can produce error with not inputting author --- debugging/book-library/script.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d3..e66163dfd 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -7,7 +7,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", @@ -16,6 +16,8 @@ function populateStorage() { ); myLibrary.push(book1); myLibrary.push(book2); + + console.log(myLibrary); render(); } } @@ -31,14 +33,16 @@ 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(); } } @@ -54,7 +58,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 @@ -76,7 +80,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"; @@ -90,11 +94,11 @@ 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 () { + 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}`); myLibrary.splice(i, 1); render(); From 910705ee4397f44afda4f30767e6e64c503ad5f0 Mon Sep 17 00:00:00 2001 From: JorvanW Date: Thu, 13 Aug 2026 15:21:44 +0100 Subject: [PATCH 02/17] added more small changes --- debugging/book-library/script.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index e66163dfd..6c8a30e4e 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -16,9 +16,6 @@ function populateStorage() { ); myLibrary.push(book1); myLibrary.push(book2); - - console.log(myLibrary); - render(); } } @@ -36,14 +33,21 @@ function submit() { author.value == null || author.value == "" || pages.value == null || - pages.value == "" + pages.value == "" || + pages.value <= 0 ) { - alert("Please fill all fields!"); + alert("Please fill all fields correctly!"); return false; } else { let book = new Book(title.value, author.value, pages.value, check.checked); myLibrary.push(book); render(); + + // resets form after input + title.value = ""; + author.value = ""; + pages.value = ""; + check.checked = false; } } @@ -70,9 +74,9 @@ function render() { 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; + titleCell.textContent = myLibrary[i].title; + authorCell.textContent = myLibrary[i].author; + pagesCell.textContent = myLibrary[i].pages; //add and wait for action for read/unread button let changeBut = document.createElement("button"); @@ -80,7 +84,7 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == true) { + if (myLibrary[i].read == true) { readStatus = "Yes"; } else { readStatus = "No"; @@ -94,7 +98,6 @@ function 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"; From ecf8d3b7710908b0ce284d6a34505654a61cdb2a Mon Sep 17 00:00:00 2001 From: JorvanW Date: Sat, 15 Aug 2026 18:09:25 +0100 Subject: [PATCH 03/17] fixed formatting errors on book-library --- debugging/book-library/index.html | 126 +++++++++++++++++------------- 1 file changed, 71 insertions(+), 55 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71e..35ddf2b2a 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,20 +1,20 @@ - + - - + + + + Book Library + + - + > + @@ -23,63 +23,79 @@

Library

Add books to your virtual library

-
-
- - - - - - -
+
- - - - - + + + + + + @@ -93,4 +109,4 @@

Library

- + \ No newline at end of file From 20e44ff04ce8737181297a01c6645a3ef7290f9f Mon Sep 17 00:00:00 2001 From: JorvanW Date: Sun, 16 Aug 2026 19:18:29 +0100 Subject: [PATCH 04/17] Removed more unnecessary sections of my code --- debugging/book-library/index.html | 12 +----------- debugging/book-library/script.js | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 35ddf2b2a..40b8f3325 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -33,7 +33,6 @@

Library

-
Library Submit
-
TitleAuthorNumber of PagesReadTitleAuthorNumber of PagesRead
@@ -96,15 +94,7 @@

Library

- - - - - - - - - +
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 6c8a30e4e..ab4bb224e 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -84,7 +84,7 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].read == true) { + if (myLibrary[i].check == true) { readStatus = "Yes"; } else { readStatus = "No"; From eb05054dd63dbaf4a2785808bd7268d45d146cad Mon Sep 17 00:00:00 2001 From: JorvanW Date: Sun, 16 Aug 2026 19:33:33 +0100 Subject: [PATCH 05/17] removed (e) from window.addEventListener --- 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 ab4bb224e..3a182c1a9 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,6 +1,6 @@ let myLibrary = []; -window.addEventListener("load", function (e) { +window.addEventListener("load", function () { populateStorage(); render(); }); From fff78c620b12db46c8acc4ac81d5783b4a5e28a6 Mon Sep 17 00:00:00 2001 From: JorvanW Date: Mon, 17 Aug 2026 15:32:13 +0100 Subject: [PATCH 06/17] updated html and js to only accept whole positive numbers --- 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 40b8f3325..0f47589af 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -59,6 +59,8 @@

Library

id="pages" name="pages" required + min="1" + step="1" >
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 3a182c1a9..be9b71672 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -34,7 +34,8 @@ function submit() { author.value == "" || pages.value == null || pages.value == "" || - pages.value <= 0 + pages.value <= 0 || + !Number.isInteger(Number(pages.value)) ) { alert("Please fill all fields correctly!"); return false; From 930918013f55b5912459a6a0daf9a9907b673238 Mon Sep 17 00:00:00 2001 From: JorvanW Date: Mon, 17 Aug 2026 15:37:44 +0100 Subject: [PATCH 07/17] switched event listener from html to javascript --- debugging/book-library/index.html | 8 ++++---- debugging/book-library/script.js | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 0f47589af..868c1a0b3 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -76,10 +76,10 @@

Library

diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index be9b71672..21e34658b 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -23,6 +23,9 @@ const title = document.getElementById("title"); const author = document.getElementById("author"); const pages = document.getElementById("pages"); const check = document.getElementById("check"); +const submitButton = document.getElementById("submitButton"); + +submitButton.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 From ac0932c44792b2c8468c5214568cd378f4b5b8e6 Mon Sep 17 00:00:00 2001 From: JorvanW Date: Mon, 17 Aug 2026 15:41:00 +0100 Subject: [PATCH 08/17] changed myLibrary declaration to const to not get reassigned --- 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 21e34658b..9c86c3b9e 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 () { populateStorage(); From 41c62983f57042c0d127f9a651115f273a3c56f6 Mon Sep 17 00:00:00 2001 From: JorvanW Date: Mon, 17 Aug 2026 15:44:41 +0100 Subject: [PATCH 09/17] removed .value = null and replace == t0 === --- debugging/book-library/script.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 9c86c3b9e..471444760 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -31,12 +31,9 @@ submitButton.addEventListener("click", submit); //via Book function and start render function function submit() { if ( - title.value == null || - title.value == "" || - author.value == null || - author.value == "" || - pages.value == null || - pages.value == "" || + title.value === "" || + author.value === "" || + pages.value === "" || pages.value <= 0 || !Number.isInteger(Number(pages.value)) ) { From b9bd1fe845f478c281c4b7db09feb6bfa0625938 Mon Sep 17 00:00:00 2001 From: JorvanW Date: Mon, 17 Aug 2026 15:54:49 +0100 Subject: [PATCH 10/17] simplified code by using bookForm.reset --- debugging/book-library/index.html | 14 +++++++------- debugging/book-library/script.js | 9 ++++----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 868c1a0b3..042710bab 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -31,7 +31,8 @@

Library

> Add new book - +
+
@@ -59,8 +60,6 @@

Library

id="pages" name="pages" required - min="1" - step="1" >
@@ -76,14 +75,15 @@

Library

+ diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 471444760..b7c3442df 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -24,6 +24,7 @@ const author = document.getElementById("author"); const pages = document.getElementById("pages"); const check = document.getElementById("check"); const submitButton = document.getElementById("submitButton"); +const bookForm = document.getElementById("bookForm"); submitButton.addEventListener("click", submit); @@ -39,16 +40,14 @@ function submit() { ) { alert("Please fill all fields correctly!"); return false; - } else { + } + { let book = new Book(title.value, author.value, pages.value, check.checked); myLibrary.push(book); render(); // resets form after input - title.value = ""; - author.value = ""; - pages.value = ""; - check.checked = false; + bookForm.reset(); } } From 214517bf40e3b8501ac49e3b2297431f9eade7fc Mon Sep 17 00:00:00 2001 From: JorvanW Date: Mon, 17 Aug 2026 16:02:12 +0100 Subject: [PATCH 11/17] updated the js to reject various number combinations for page inputs --- 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 b7c3442df..c800fb2b8 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -36,7 +36,7 @@ function submit() { author.value === "" || pages.value === "" || pages.value <= 0 || - !Number.isInteger(Number(pages.value)) + !/^[1-9]\d*$/.test(pages.value) ) { alert("Please fill all fields correctly!"); return false; From 5873142b15104f785e0e61149d6acc18adaa2bf4 Mon Sep 17 00:00:00 2001 From: JorvanW Date: Mon, 17 Aug 2026 16:07:32 +0100 Subject: [PATCH 12/17] updated js and html to no longer delete every table one by one but to instead clear all at once --- debugging/book-library/index.html | 2 +- debugging/book-library/script.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 042710bab..b245658ee 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -96,7 +96,7 @@

Library

- +
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index c800fb2b8..114a40c54 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -25,6 +25,7 @@ const pages = document.getElementById("pages"); const check = document.getElementById("check"); const submitButton = document.getElementById("submitButton"); const bookForm = document.getElementById("bookForm"); +const bookTableBody = document.getElementById("bookTableBody"); submitButton.addEventListener("click", submit); @@ -62,9 +63,8 @@ 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); - } + bookTableBody.innerHTML = ""; + //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { From 53cde0545b354a49a2f1f799ffbc0daf4a2e7fe9 Mon Sep 17 00:00:00 2001 From: JorvanW Date: Mon, 17 Aug 2026 16:22:07 +0100 Subject: [PATCH 13/17] cleaned up some code and removed id attribute --- debugging/book-library/script.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 114a40c54..69dfe8db9 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -41,8 +41,7 @@ function submit() { ) { alert("Please fill all fields correctly!"); return false; - } - { + let book = new Book(title.value, author.value, pages.value, check.checked); myLibrary.push(book); render(); @@ -60,15 +59,13 @@ function Book(title, author, pages, check) { } function render() { - let table = document.getElementById("display"); - let rowsNumber = table.rows.length; //delete old table bookTableBody.innerHTML = ""; //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { - let row = table.insertRow(1); + let row = bookTableBody.insertRow(); let titleCell = row.insertCell(0); let authorCell = row.insertCell(1); let pagesCell = row.insertCell(2); @@ -80,17 +77,9 @@ 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 = ""; - if (myLibrary[i].check == true) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } - changeBut.innerText = readStatus; - + myLibrary[i].check ? "Yes" : "No"; changeBut.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check; render(); From 165351f0903f431b66f7b4c1a60ee30860016855 Mon Sep 17 00:00:00 2001 From: JorvanW Date: Mon, 17 Aug 2026 16:24:09 +0100 Subject: [PATCH 14/17] fixed errors stopping page from loading --- 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 69dfe8db9..1c7afb7a3 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -41,7 +41,8 @@ function submit() { ) { alert("Please fill all fields correctly!"); return false; - + } + { let book = new Book(title.value, author.value, pages.value, check.checked); myLibrary.push(book); render(); From 641cfe02c3cfe13b96810563c2534bc983343fc1 Mon Sep 17 00:00:00 2001 From: JorvanW Date: Mon, 17 Aug 2026 16:35:28 +0100 Subject: [PATCH 15/17] reorder sequence of delete button and added timeout function to make the book delete before the alert message is passed --- debugging/book-library/script.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 1c7afb7a3..ea9788d56 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -90,11 +90,16 @@ function render() { let delButton = document.createElement("button"); deleteCell.appendChild(delButton); delButton.className = "btn btn-warning"; - delButton.innerHTML = "Delete"; + delButton.textContent = "Delete"; + delButton.addEventListener("click", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); + let deletedTitle = myLibrary[i].title; myLibrary.splice(i, 1); render(); + + setTimeout(function () { + alert(`You've deleted title: ${deletedTitle}`); + }, 0); }); } } From 64c48cb22130842d936d5d01abbac97ad5b9ddd0 Mon Sep 17 00:00:00 2001 From: JorvanW Date: Tue, 18 Aug 2026 14:21:50 +0100 Subject: [PATCH 16/17] fixed min value in input tag and trimmed author and title values --- debugging/book-library/index.html | 4 +++- debugging/book-library/script.js | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index b245658ee..05f51fb06 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -41,7 +41,9 @@

Library

class="form-control" id="title" name="title" - required + min = "1" + required + > diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index ea9788d56..a7823f267 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -43,7 +43,12 @@ function submit() { return false; } { - let book = new Book(title.value, author.value, pages.value, check.checked); + let book = new Book( + title.value.trim(), + author.value.trim(), + pages.value, + check.checked + ); myLibrary.push(book); render(); From e52b152e3d1bfd2445e72adb775d02780aea1c9b Mon Sep 17 00:00:00 2001 From: JorvanW Date: Tue, 18 Aug 2026 14:28:53 +0100 Subject: [PATCH 17/17] fixed eventListenter and get button details --- debugging/book-library/index.html | 5 ++--- debugging/book-library/script.js | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 05f51fb06..539a1ced7 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -76,10 +76,9 @@

Library

- diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index a7823f267..86e11fda7 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -23,7 +23,7 @@ const title = document.getElementById("title"); const author = document.getElementById("author"); const pages = document.getElementById("pages"); const check = document.getElementById("check"); -const submitButton = document.getElementById("submitButton"); +const submitButton = document.getElementById("submit-button"); const bookForm = document.getElementById("bookForm"); const bookTableBody = document.getElementById("bookTableBody");