From 4da0a58f083150c9bbbd9912e7f3fcfe2bd6ef4d Mon Sep 17 00:00:00 2001 From: djebsoft Date: Fri, 24 Apr 2026 00:07:04 +0100 Subject: [PATCH 01/12] fixing bugs in js code --- debugging/book-library/script.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..813c1c02 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,7 +16,6 @@ function populateStorage() { ); myLibrary.push(book1); myLibrary.push(book2); - render(); } } @@ -31,14 +30,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 +55,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 @@ -75,13 +76,8 @@ function render() { changeBut.id = i; changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); - let readStatus = ""; - if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } - changeBut.innerText = readStatus; + + changeBut.innerText = myLibrary[i].check ? "Yes" : "No"; changeBut.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check; @@ -89,12 +85,12 @@ 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"; 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 cea830495d45177e57630674fca3c18ccd88bb65 Mon Sep 17 00:00:00 2001 From: djebsoft Date: Mon, 18 May 2026 06:20:34 +0100 Subject: [PATCH 02/12] adding more constraints on user inputs --- .vscode/settings.json | 3 +++ debugging/book-library/script.js | 29 +++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..4c7ff40f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5502 +} diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 813c1c02..335c60bc 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -27,21 +27,26 @@ 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 || - title.value == "" || - author.value == null || - author.value == "" || - pages.value == null || - pages.value == "" - ) { - alert("Please fill all fields!"); + const trimmedTitle = title.value.trim() + const trimmedAuthor = author.value.trim() + const pagesInt = parseInt(pages.value, 10) + if (trimmesTitle === "") { + alert("please enter a title.") return false; - } else { - let book = new Book(title.value, author.value, pages.value, check.checked); + } + if (trimmedAuthor === ""){ + alert("please enter an author.") + return false; + } + if (isNaN(pagesInt) || pagesInt <= 0){ + alert("please enter a valid number of pages") + return false; + } + + let book = new Book(trimmedTitle, trimmedAuthor, pagesInt, check.checked); myLibrary.push(book); render(); - } + } function Book(title, author, pages, check) { From af7b21430bdf01039ea848b61df95cb62521c7e8 Mon Sep 17 00:00:00 2001 From: djebsoft Date: Mon, 18 May 2026 06:26:39 +0100 Subject: [PATCH 03/12] fixed typo --- debugging/book-library/script.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 335c60bc..7f94f43a 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -29,18 +29,18 @@ const check = document.getElementById("check"); function submit() { const trimmedTitle = title.value.trim() const trimmedAuthor = author.value.trim() - const pagesInt = parseInt(pages.value, 10) - if (trimmesTitle === "") { - alert("please enter a title.") + const pagesInt = parseInt(pages.value, 10); + if (trimmedTitle === "") { + alert("Please enter a title."); return false; } if (trimmedAuthor === ""){ - alert("please enter an author.") + alert("Please enter an author."); return false; } if (isNaN(pagesInt) || pagesInt <= 0){ - alert("please enter a valid number of pages") - return false; + alert("Please enter a valid number of pages"); + return false; } let book = new Book(trimmedTitle, trimmedAuthor, pagesInt, check.checked); From 8beb4f452213f4bb5ea3cb00422bddd4fc4ac9ed Mon Sep 17 00:00:00 2001 From: djebsoft Date: Mon, 18 May 2026 06:43:23 +0100 Subject: [PATCH 04/12] updated the code to delete all rows in one operation --- debugging/book-library/script.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 7f94f43a..131125f0 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -58,11 +58,7 @@ 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); - } +table.tBodies[0].innerHTML = ""; //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { From 5f3a2a84137535f575009f1d37d647e44e033e58 Mon Sep 17 00:00:00 2001 From: djebsoft Date: Mon, 18 May 2026 06:53:36 +0100 Subject: [PATCH 05/12] removed unecessary assignement to the buttons --- 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 131125f0..e16dc29a 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -74,7 +74,6 @@ table.tBodies[0].innerHTML = ""; //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); @@ -87,7 +86,6 @@ table.tBodies[0].innerHTML = ""; //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 4528c687b4d70226c4c994ba89b375add6fbaf35 Mon Sep 17 00:00:00 2001 From: djebsoft Date: Mon, 18 May 2026 06:58:30 +0100 Subject: [PATCH 06/12] made sure the message displays after the operation is successfully completed --- 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 e16dc29a..eb6b998c 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -90,8 +90,8 @@ table.tBodies[0].innerHTML = ""; delBut.className = "btn btn-warning"; delBut.innerHTML = "Delete"; delBut.addEventListener("click", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); + alert(`You've deleted title: ${myLibrary[i].title}`); render(); }); } From 85b686459dd080338b986e54acd2b76831e891cf Mon Sep 17 00:00:00 2001 From: djebsoft Date: Mon, 18 May 2026 07:10:55 +0100 Subject: [PATCH 07/12] matching the upstream --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4c7ff40f..e69de29b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +0,0 @@ -{ - "liveServer.settings.port": 5502 -} From 48e42d3e65b583552129152537adeeb17e0b7f0b Mon Sep 17 00:00:00 2001 From: djebsoft Date: Mon, 18 May 2026 07:19:29 +0100 Subject: [PATCH 08/12] matching the upstream --- .vscode/settings.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e69de29b..00000000 From 5a494d45188dbeff3d110f7cab2332bda8d6963a Mon Sep 17 00:00:00 2001 From: djebsoft Date: Mon, 18 May 2026 07:31:44 +0100 Subject: [PATCH 09/12] fixed typo --- debugging/book-library/script.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index eb6b998c..94c576d8 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -44,9 +44,8 @@ function submit() { } let book = new Book(trimmedTitle, trimmedAuthor, pagesInt, check.checked); - myLibrary.push(book); - render(); - + myLibrary.push(book); + render(); } function Book(title, author, pages, check) { @@ -58,7 +57,7 @@ function Book(title, author, pages, check) { function render() { let table = document.getElementById("display"); -table.tBodies[0].innerHTML = ""; + table.tBodies[0].innerHTML = ""; //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { From abdd8ea791fe36a5511a1d1c8e4f3a28bd6beb3d Mon Sep 17 00:00:00 2001 From: djebsoft Date: Mon, 18 May 2026 08:25:59 +0100 Subject: [PATCH 10/12] fixed the code to insert row into the right element --- 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 94c576d8..00cf5835 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -27,22 +27,22 @@ 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() { - const trimmedTitle = title.value.trim() - const trimmedAuthor = author.value.trim() + const trimmedTitle = title.value.trim(); + const trimmedAuthor = author.value.trim(); const pagesInt = parseInt(pages.value, 10); if (trimmedTitle === "") { alert("Please enter a title."); return false; } - if (trimmedAuthor === ""){ + if (trimmedAuthor === "") { alert("Please enter an author."); return false; } - if (isNaN(pagesInt) || pagesInt <= 0){ + if (isNaN(pagesInt) || pagesInt <= 0) { alert("Please enter a valid number of pages"); return false; } - + let book = new Book(trimmedTitle, trimmedAuthor, pagesInt, check.checked); myLibrary.push(book); render(); @@ -61,7 +61,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.tBodies[0].insertRow(-1); let titleCell = row.insertCell(0); let authorCell = row.insertCell(1); let pagesCell = row.insertCell(2); @@ -89,8 +89,8 @@ function render() { delBut.className = "btn btn-warning"; delBut.innerHTML = "Delete"; delBut.addEventListener("click", function () { - myLibrary.splice(i, 1); alert(`You've deleted title: ${myLibrary[i].title}`); + myLibrary.splice(i, 1); render(); }); } From 56c565fa6cf45ffa5508a5acda1fe7dd30846b3d Mon Sep 17 00:00:00 2001 From: djebsoft Date: Mon, 18 May 2026 21:53:40 +0100 Subject: [PATCH 11/12] fixed syntax errors --- 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..f8fea89c 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,12 +1,9 @@ - - + + - - + My Book Library App + + @@ -31,7 +28,7 @@

Library

Library /> Library type="submit" value="Submit" class="btn btn-primary" - onclick="submit();" + onclick="submit()" />
From 53b6602ae66b68cc81833968df6dab819461900a Mon Sep 17 00:00:00 2001 From: djebsoft Date: Tue, 19 May 2026 07:00:12 +0100 Subject: [PATCH 12/12] added type module and made the required changes --- debugging/book-library/index.html | 4 ++-- debugging/book-library/script.js | 27 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index f8fea89c..89cbc73e 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="submit" /> @@ -88,6 +88,6 @@

Library

- + diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 00cf5835..51bcc1a5 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -3,6 +3,7 @@ let myLibrary = []; window.addEventListener("load", function (e) { populateStorage(); render(); + document.getElementById("submit").addEventListener("click", submit) }); function populateStorage() { @@ -19,17 +20,17 @@ 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"); //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() { - const trimmedTitle = title.value.trim(); - const trimmedAuthor = author.value.trim(); - const pagesInt = parseInt(pages.value, 10); + const trimmedTitle = titleInput.value.trim(); + const trimmedAuthor = authorInput.value.trim(); + const pagesInt = parseInt(pagesInput.value, 10); if (trimmedTitle === "") { alert("Please enter a title."); return false; @@ -43,7 +44,12 @@ function submit() { return false; } - let book = new Book(trimmedTitle, trimmedAuthor, pagesInt, check.checked); + let book = new Book( + trimmedTitle, + trimmedAuthor, + pagesInt, + checkInput.checked + ); myLibrary.push(book); render(); } @@ -57,11 +63,12 @@ function Book(title, author, pages, check) { function render() { let table = document.getElementById("display"); - table.tBodies[0].innerHTML = ""; + let tbody = table.tBodies[0]; + tbody.innerHTML = ""; //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { - let row = table.tBodies[0].insertRow(-1); + let row = tbody.insertRow(-1); let titleCell = row.insertCell(0); let authorCell = row.insertCell(1); let pagesCell = row.insertCell(2);