From d0f5bcd74c0e47fbd1182eb1bf0543b9569b4cca Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Wed, 29 Jul 2026 13:46:14 +0100 Subject: [PATCH 1/9] update book --- 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 75ce6c1d3..1bad6a6f3 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 @@ -90,11 +90,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 ef308cb4bc835bbb7f6e297d8e26acaa03ff6b5c Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Thu, 30 Jul 2026 11:13:44 +0100 Subject: [PATCH 2/9] fix all the bug --- .vscode/launch.json | 13 +++++++++++++ debugging/book-library/script.js | 22 +++++++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..aab663782 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://127.0.0.1:5500/debugging/book-library/index.html", + "webRoot": "${workspaceFolder}/debugging/book-library" + } + ] +} \ No newline at end of file diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 1bad6a6f3..147633082 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -16,7 +16,6 @@ function populateStorage() { ); myLibrary.push(book1); myLibrary.push(book2); - render(); } } @@ -28,17 +27,13 @@ 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 == "" || - pages.value == null || - pages.value == "" - ) { + console.log("1. The submit button was clicked!"); + if (title.value == "" || author.value == "" || 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(); } } @@ -51,6 +46,7 @@ function Book(title, author, pages, check) { } function render() { + console.log("🎨 render() function just ran!"); let table = document.getElementById("display"); let rowsNumber = table.rows.length; //delete old table @@ -60,7 +56,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); @@ -77,9 +73,9 @@ function render() { wasReadCell.appendChild(changeBut); let readStatus = ""; if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { readStatus = "No"; + } else { + readStatus = "Yes"; } changeBut.innerText = readStatus; @@ -89,7 +85,7 @@ 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); From 8201a6651173297961c6f183d0a12b4b55d3f20f Mon Sep 17 00:00:00 2001 From: "Arthur C." Date: Tue, 18 Aug 2026 09:19:52 +0100 Subject: [PATCH 3/9] Delete .vscode/launch.json --- .vscode/launch.json | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index aab663782..000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - - { - "type": "chrome", - "request": "launch", - "name": "Launch Chrome against localhost", - "url": "http://127.0.0.1:5500/debugging/book-library/index.html", - "webRoot": "${workspaceFolder}/debugging/book-library" - } - ] -} \ No newline at end of file From 8d8b3de83204a5bd8d2520ca705e487c8a0cb888 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Wed, 19 Aug 2026 11:26:37 +0100 Subject: [PATCH 4/9] update script.js --- 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 147633082..670a25b39 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,5 +1,5 @@ let myLibrary = []; - +//event listener window.addEventListener("load", function (e) { populateStorage(); render(); @@ -98,3 +98,4 @@ function render() { }); } } + From 08e29677f2d3dcd3d7303c0ececc899daad2339f Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Wed, 19 Aug 2026 21:40:21 +0100 Subject: [PATCH 5/9] New update No alert --- debugging/book-library/script.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 670a25b39..0a2b9ba13 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) { + if (myLibrary.length === 0) { let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); let book2 = new Book( "The Old Man and the Sea", @@ -27,9 +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() { - console.log("1. The submit button was clicked!"); - if (title.value == "" || author.value == "" || pages.value == "") { - alert("Please fill all fields!"); + if (title.value === "" || author.value === "" || pages.value === "") { return false; } else { let book = new Book(title.value, author.value, pages.value, check.checked); @@ -62,9 +60,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"); @@ -72,7 +70,7 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == false) { + if (myLibrary[i].check === false) { readStatus = "No"; } else { readStatus = "Yes"; @@ -87,15 +85,12 @@ function render() { //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"; delBut.addEventListener("click", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); }); } } - From 6853b59f9d02d6dfd0fc61db48160d57961fb50b Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Thu, 20 Aug 2026 00:47:41 +0100 Subject: [PATCH 6/9] Align the general feedback --- debugging/book-library/script.js | 35 +++++++++++++------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 0a2b9ba13..8f1c61bce 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -2,12 +2,11 @@ let myLibrary = []; //event listener window.addEventListener("load", function (e) { populateStorage(); - render(); }); 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", @@ -19,10 +18,10 @@ 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 @@ -44,13 +43,13 @@ function Book(title, author, pages, check) { } function render() { - console.log("🎨 render() function just ran!"); - let table = document.getElementById("display"); + const table = document.getElementById("display"); + table.innerHTML = ""; let rowsNumber = table.rows.length; //delete old table - for (let n = rowsNumber - 1; n > 0; n--) { - table.deleteRow(n); - } + const tobody = table.querySelector("tbody") || table; + tobody.innerHTML = ""; + //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { @@ -65,17 +64,11 @@ function render() { pagesCell.textContent = myLibrary[i].pages; //add and wait for action for read/unread button - let changeBut = document.createElement("button"); - changeBut.id = i; + const changeBut = document.createElement("button"); changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check === false) { - readStatus = "No"; - } else { - readStatus = "Yes"; - } - changeBut.innerText = readStatus; + changeBut.textContent = myLibrary[i].check ? "Yes" : "No"; changeBut.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check; @@ -84,10 +77,10 @@ function render() { //add delete button to every row and render again - let delBut = document.createElement("button"); + const delBut = document.createElement("button"); deleteCell.appendChild(delBut); delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; + delBut.textContent = "Delete"; delBut.addEventListener("click", function () { myLibrary.splice(i, 1); render(); From 398ad4668edbe33239ca4b0125dcfcabd7f658e2 Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Fri, 21 Aug 2026 00:42:45 +0100 Subject: [PATCH 7/9] Update index and script.js --- debugging/book-library/index.html | 20 +++++++------------- debugging/book-library/script.js | 27 +++++++++++++++++++-------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71e..54efff322 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,7 +1,7 @@ - + - + Book Library Library
+
Library class="form-control" id="pages" name="pages" - required /> - +
+
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 8f1c61bce..67b66c1e9 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,4 +1,4 @@ -let myLibrary = []; +const myLibrary = []; //event listener window.addEventListener("load", function (e) { populateStorage(); @@ -10,7 +10,7 @@ function populateStorage() { let book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", - "127", + 127, true ); myLibrary.push(book1); @@ -25,14 +25,24 @@ 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() { - if (title.value === "" || author.value === "" || pages.value === "") { +function processbook() { + const trimmedTitle = title.value.trim(); + const trimmedAuthor = author.value.trim(); + const pagesNum = Number(pages.value); + + if ( + !trimmedTitle || + !trimmedAuthor || + !Number.isInteger(pagesNum) || + pagesNum <= 0 + ) { + alert("Please enter a valid title, author, and a whole number of pages."); return false; - } else { - let book = new Book(title.value, author.value, pages.value, check.checked); - myLibrary.push(book); - render(); } + + let book = new Book(trimmedTitle, trimmedAuthor, pagesNum, check.checked); + myLibrary.push(book); + render(); } function Book(title, author, pages, check) { @@ -82,6 +92,7 @@ function render() { delBut.className = "btn btn-warning"; delBut.textContent = "Delete"; delBut.addEventListener("click", function () { + alert("Are you sure you want to delete the book ?"); myLibrary.splice(i, 1); render(); }); From 0c6a2d9fa34d20bc4cf41a94f5a9c8efca16ec1a Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Fri, 21 Aug 2026 20:53:16 +0100 Subject: [PATCH 8/9] latest update preventDefault --- debugging/book-library/index.html | 68 +++++++++++++------------------ debugging/book-library/script.js | 21 ++++++---- 2 files changed, 41 insertions(+), 48 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 54efff322..55afa7af7 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,12 +1,9 @@ - + - Book Library - + Book Library + + @@ -28,40 +25,31 @@

Library

-
-
- - - - - - -
+
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 67b66c1e9..acc8fd4df 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -25,7 +25,11 @@ 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 processbook() { +const submitBtn = document.getElementById("submit-btn"); +function processbook(event) { + // Prevent the form from refreshing the page + event.preventDefault(); + const trimmedTitle = title.value.trim(); const trimmedAuthor = author.value.trim(); const pagesNum = Number(pages.value); @@ -44,6 +48,7 @@ function processbook() { myLibrary.push(book); render(); } +submitBtn.addEventListener("click", processbook); function Book(title, author, pages, check) { this.title = title; @@ -55,10 +60,6 @@ function Book(title, author, pages, check) { function render() { const table = document.getElementById("display"); table.innerHTML = ""; - let rowsNumber = table.rows.length; - //delete old table - const tobody = table.querySelector("tbody") || table; - tobody.innerHTML = ""; //insert updated row and cells let length = myLibrary.length; @@ -92,9 +93,13 @@ function render() { delBut.className = "btn btn-warning"; delBut.textContent = "Delete"; delBut.addEventListener("click", function () { - alert("Are you sure you want to delete the book ?"); - myLibrary.splice(i, 1); - render(); + const bookTitle = myLibrary[i].title; + + // 2. Ask for confirmation with 'OK' and 'Cancel' options + if (confirm(`Are you sure you want to delete "${bookTitle}"?`)) { + myLibrary.splice(i, 1); + render(); + } }); } } From 84cb3e62a201eac857dfa25036f94dd2e0507aba Mon Sep 17 00:00:00 2001 From: Arthur <> Date: Sat, 22 Aug 2026 10:01:21 +0100 Subject: [PATCH 9/9] FInally finished- Table --- debugging/book-library/script.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index acc8fd4df..2e418756d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -58,13 +58,13 @@ function Book(title, author, pages, check) { } function render() { - const table = document.getElementById("display"); - table.innerHTML = ""; + const tbody = document.querySelector("#display tbody"); + tbody.innerHTML = ""; //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { - let row = table.insertRow(-1); + let row = tbody.insertRow(-1); let titleCell = row.insertCell(0); let authorCell = row.insertCell(1); let pagesCell = row.insertCell(2);