From d7e7b4c954ca733135bda1a2bccde2af14f645de Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 17:47:07 +0100 Subject: [PATCH 01/19] fix error in render function for loo closing missing closing bracket --- 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 75ce6c1d..222d0b76 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,5 +1,5 @@ let myLibrary = []; - +it window.addEventListener("load", function (e) { populateStorage(); render(); @@ -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 11e500e7c6063c51b7ec3bfdec3880e682efff97 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 19:15:19 +0100 Subject: [PATCH 02/19] update delete button --- debugging/book-library/script.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 222d0b76..21e79ebf 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,5 +1,4 @@ let myLibrary = []; -it window.addEventListener("load", function (e) { populateStorage(); render(); @@ -38,7 +37,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,7 +88,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); delBut.className = "btn btn-warning"; @@ -101,3 +100,18 @@ function render() { }); } } +// My website should be able to: + +// - View a list of books that I've read +// - Add books to a list of books that I've read +// - Including title, author, number of pages and if I've read it +// - If any of the information is missing it shouldn't add the book and should show an alert +// - Remove books from my list + +// ## Bugs to be fixed + +// 1. Website loads but doesn't show any books +// 2. Error in console when you try to add a book +// 3. It uses the title name as the author name +// 4. Delete button is broken +// 5. When I add a book that I say I've read - it saves the wrong answer \ No newline at end of file From de9d89d280d60bb2fd874de45fb9e66cff2f9ff0 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 20:55:46 +0100 Subject: [PATCH 03/19] update add book function and inputs --- debugging/book-library/index.html | 2 +- debugging/book-library/script.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..e24a68f3 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();" + id ="submit-btn" /> diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 21e79ebf..2c35bb52 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -15,7 +15,6 @@ function populateStorage() { ); myLibrary.push(book1); myLibrary.push(book2); - render(); } } @@ -23,6 +22,12 @@ const title = document.getElementById("title"); const author = document.getElementById("author"); const pages = document.getElementById("pages"); const check = document.getElementById("check"); +const submitBtn = document.getElementById("submit-btn"); + +submitBtn.addEventListener("click", function (event) { + event.preventDefault(); + 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 @@ -36,7 +41,7 @@ function submit() { 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(); } @@ -55,7 +60,7 @@ function render() { //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++) { @@ -110,7 +115,7 @@ function render() { // ## Bugs to be fixed -// 1. Website loads but doesn't show any books +// 1. Website loads but doesn't show any books => fixed // 2. Error in console when you try to add a book // 3. It uses the title name as the author name // 4. Delete button is broken From 3dadc55f78fa39a9b252720f0bb2844aa4c32133 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 21:35:49 +0100 Subject: [PATCH 04/19] fixed delete button --- 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 2c35bb52..31ec0fd4 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -81,9 +81,9 @@ function render() { wasReadCell.appendChild(changeBut); let readStatus = ""; if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { readStatus = "No"; + } else { + readStatus = "Yes"; } changeBut.innerText = readStatus; @@ -98,7 +98,7 @@ function render() { 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(); @@ -116,7 +116,7 @@ function render() { // ## Bugs to be fixed // 1. Website loads but doesn't show any books => fixed -// 2. Error in console when you try to add a book -// 3. It uses the title name as the author name -// 4. Delete button is broken -// 5. When I add a book that I say I've read - it saves the wrong answer \ No newline at end of file +// 2. Error in console when you try to add a book => fixed +// 3. It uses the title name as the author name => fixed +// 4. Delete button is broken =>git +// 5. When I add a book that I say I've read - it saves the wrong answer => \ No newline at end of file From 9fb77a91e8f2ff8478f497b30d537693bdc99d04 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 21:37:23 +0100 Subject: [PATCH 05/19] removed unused comment --- debugging/book-library/script.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 31ec0fd4..9537130d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -105,18 +105,3 @@ function render() { }); } } -// My website should be able to: - -// - View a list of books that I've read -// - Add books to a list of books that I've read -// - Including title, author, number of pages and if I've read it -// - If any of the information is missing it shouldn't add the book and should show an alert -// - Remove books from my list - -// ## Bugs to be fixed - -// 1. Website loads but doesn't show any books => fixed -// 2. Error in console when you try to add a book => fixed -// 3. It uses the title name as the author name => fixed -// 4. Delete button is broken =>git -// 5. When I add a book that I say I've read - it saves the wrong answer => \ No newline at end of file From da350c1b05e012bd77dcc1db519b2fb3838225ea Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 22:06:37 +0100 Subject: [PATCH 06/19] unco changes in html --- debugging/book-library/script.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 9537130d..a8b24945 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -105,3 +105,21 @@ function render() { }); } } +<<<<<<< HEAD +======= +// My website should be able to: + +// - View a list of books that I've read +// - Add books to a list of books that I've read +// - Including title, author, number of pages and if I've read it +// - If any of the information is missing it shouldn't add the book and should show an alert +// - Remove books from my list + +// ## Bugs to be fixed + +// 1. Website loads but doesn't show any books => fixed +// 2. Error in console when you try to add a book => fixed +// 3. It uses the title name as the author name => fixed +// 4. Delete button is broken =>git +// 5. When I add a book that I say I've read - it saves the wrong answer => +>>>>>>> c637046 (unco changes in html) From 2132c95b8f03a4960604cb1e437d4973ec040b62 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 15 Apr 2026 22:56:11 +0100 Subject: [PATCH 07/19] removed unused comment --- debugging/book-library/script.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index a8b24945..c7da752c 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -105,21 +105,4 @@ function render() { }); } } -<<<<<<< HEAD -======= -// My website should be able to: -// - View a list of books that I've read -// - Add books to a list of books that I've read -// - Including title, author, number of pages and if I've read it -// - If any of the information is missing it shouldn't add the book and should show an alert -// - Remove books from my list - -// ## Bugs to be fixed - -// 1. Website loads but doesn't show any books => fixed -// 2. Error in console when you try to add a book => fixed -// 3. It uses the title name as the author name => fixed -// 4. Delete button is broken =>git -// 5. When I add a book that I say I've read - it saves the wrong answer => ->>>>>>> c637046 (unco changes in html) From 856dff76bc4f427dfd0f1018ab68297a963a542f Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 17 Apr 2026 18:37:19 +0100 Subject: [PATCH 08/19] validate html code --- debugging/book-library/index.html | 146 ++++++++++++------------------ debugging/book-library/script.js | 1 + 2 files changed, 58 insertions(+), 89 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index e24a68f3..87bd1542 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,96 +1,64 @@ - - - - - - - - - - + - -
-

Library

-

Add books to your virtual library

-
+ + + + Book Library + + + + + + + + +
+

Library

+

Add books to your virtual library

+
- + -
-
- - - - - - - - -
+
+
+ + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + +
TitleAuthorNumber of PagesRead
- - - - - - - - - - - - - - - - - - - -
TitleAuthorNumber of PagesRead
+ + - - - + \ No newline at end of file diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index c7da752c..6e577ada 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -106,3 +106,4 @@ function render() { } } + From 341fdedcb356156e0750af3b4b8a3dad4aaa6bad Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 17 Apr 2026 18:52:28 +0100 Subject: [PATCH 09/19] refactor page count with number type and update element variable names --- debugging/book-library/index.html | 2 +- debugging/book-library/script.js | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 87bd1542..55d58a46 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -58,7 +58,7 @@

Library

- + \ No newline at end of file diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 6e577ada..fd25116d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -6,11 +6,11 @@ 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("Robison Crusoe", "Daniel Defoe", 252, true); let book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", - "127", + 127, true ); myLibrary.push(book1); @@ -18,13 +18,13 @@ function populateStorage() { } } -const title = document.getElementById("title"); -const author = document.getElementById("author"); -const pages = document.getElementById("pages"); -const check = document.getElementById("check"); -const submitBtn = document.getElementById("submit-btn"); +const titleEl = document.getElementById("title"); +const authorEl = document.getElementById("author"); +const pagesEl = document.getElementById("pages"); +const checkEl = document.getElementById("check"); +const submitBtnEl = document.getElementById("submit-btn"); -submitBtn.addEventListener("click", function (event) { +submitBtnEl.addEventListener("click", function (event) { event.preventDefault(); submit(); }); @@ -33,15 +33,15 @@ submitBtn.addEventListener("click", function (event) { //via Book function and start render function function submit() { if ( - title.value == null || - title.value == "" || - pages.value == null || - pages.value == "" + titleEl.value == null || + titleEl.value == "" || + pagesEl.value == null || + pagesEl.value == "" ) { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, author.value, pages.value, check.checked); + let book = new Book(titleEl.value, authorEl.value, pagesEl.value, checkEl.checked); myLibrary.push(book); render(); } From 2a37c415da83690cbb26d9e21defd144282acb1a Mon Sep 17 00:00:00 2001 From: marthak1 Date: Sat, 18 Apr 2026 12:01:38 +0100 Subject: [PATCH 10/19] refactor submit function by using logical NOT to validate input --- debugging/book-library/index.html | 3 ++- debugging/book-library/script.js | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 55d58a46..5f381d06 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -61,4 +61,5 @@

Library

- \ No newline at end of file + + diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index fd25116d..0f77880d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -33,10 +33,9 @@ submitBtnEl.addEventListener("click", function (event) { //via Book function and start render function function submit() { if ( - titleEl.value == null || - titleEl.value == "" || - pagesEl.value == null || - pagesEl.value == "" + !titleEl.value || + !authorEl.value || + !pagesEl.value ) { alert("Please fill all fields!"); return false; From 3ba292d023c019c82367e94e8d5f9c032c8acd4a Mon Sep 17 00:00:00 2001 From: marthak1 Date: Sat, 18 Apr 2026 12:57:56 +0100 Subject: [PATCH 11/19] add html input validation --- .vscode/settings.json | 3 +++ debugging/book-library/index.html | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..30de70fe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.acceptSuggestionOnEnter": "on" +} \ No newline at end of file diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 5f381d06..e554b011 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -25,16 +25,16 @@

Library

- + - + - + -
+
From fa04d30b138feed6bbbabe904c54635b2605a33b Mon Sep 17 00:00:00 2001 From: marthak1 Date: Mon, 20 Apr 2026 19:14:46 +0100 Subject: [PATCH 12/19] add efficient approach to remove rows in table, add delete all button , add alert message after book deletion --- debugging/book-library/script.js | 61 ++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 0f77880d..714106f7 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -6,8 +6,8 @@ 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, @@ -40,7 +40,7 @@ function submit() { alert("Please fill all fields!"); return false; } else { - let book = new Book(titleEl.value, authorEl.value, pagesEl.value, checkEl.checked); + const book = new Book(titleEl.value, authorEl.value, pagesEl.value, checkEl.checked); myLibrary.push(book); render(); } @@ -53,13 +53,19 @@ function Book(title, author, pages, check) { this.check = check; } +function showMessage(text) { + const msg = document.createElement("p"); + msg.textContent = text; + document.body.appendChild(msg); + + setTimeout(() => msg.remove(), 2000); +} function render() { - let table = document.getElementById("display"); - let rowsNumber = table.rows.length; + const table = document.getElementById("display"); //delete old table - for (let n = rowsNumber - 1; n > 0; n--){ - table.deleteRow(n); - } + while (table.rows.length > 1) { + table.deleteRow(1); + } //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { @@ -69,40 +75,49 @@ 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"); + const changeBut = document.createElement("button"); changeBut.id = i; changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); - let readStatus = ""; - if (myLibrary[i].check == false) { - readStatus = "No"; - } else { - readStatus = "Yes"; - } - changeBut.innerText = readStatus; - + changeBut.innerText = myLibrary[i].check ? "Yes" : "No"; changeBut.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check; render(); }); //add delete button to every row and render again - let delBut = document.createElement("button"); + const 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}`); + const deletedTitle = myLibrary[i].title; myLibrary.splice(i, 1); render(); + showMessage(`You've deleted: ${deletedTitle}`); }); - } + } } +const deleteAllBtn = document.createElement("button"); +deleteAllBtn.textContent = "Delete All"; +deleteAllBtn.className = "btn btn-danger"; +document.body.appendChild(deleteAllBtn); +deleteAllBtn.addEventListener("click", function () { + if (myLibrary.length === 0) return; + + const count = myLibrary.length; + + myLibrary.length = 0; // clear all + deleteAllBtn.disabled = myLibrary.length === 0; + render(); + + showMessage(`Deleted all ${count} books`); +}); From fc525cebc3fc69dff9df816cff3fbcda76f89ca2 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Mon, 20 Apr 2026 19:35:12 +0100 Subject: [PATCH 13/19] add form validation in js --- debugging/book-library/script.js | 34 ++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 714106f7..6d3cbdcc 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -32,18 +32,32 @@ submitBtnEl.addEventListener("click", function (event) { //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 ( - !titleEl.value || - !authorEl.value || - !pagesEl.value - ) { + const title = titleEl.value.trim(); + const author = authorEl.value.trim(); + const pagesRaw = pagesEl.value.trim(); + + if (!title || !author || !pagesRaw) { alert("Please fill all fields!"); - return false; - } else { - const book = new Book(titleEl.value, authorEl.value, pagesEl.value, checkEl.checked); - myLibrary.push(book); - render(); + return; + } + + const pages = Number(pagesRaw); + + if (!Number.isInteger(pages) || pages <= 0) { + alert("Pages must be a positive number"); + return; } + + const book = new Book(title, author, pages, checkEl.checked); + + myLibrary.push(book); + render(); + + // clear form + titleEl.value = ""; + authorEl.value = ""; + pagesEl.value = ""; + checkEl.checked = false; } function Book(title, author, pages, check) { From da4c5db894308eee69d0eecd38fec880b8e1aa7e Mon Sep 17 00:00:00 2001 From: marthak1 <60424466+marthak1@users.noreply.github.com> Date: Mon, 20 Apr 2026 19:49:06 +0100 Subject: [PATCH 14/19] Delete .vscode/settings.json --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 30de70fe..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "editor.acceptSuggestionOnEnter": "on" -} \ No newline at end of file From b7cf82893a635955d61af193005f129be2396304 Mon Sep 17 00:00:00 2001 From: marthak1 <60424466+marthak1@users.noreply.github.com> Date: Tue, 21 Apr 2026 19:30:18 +0100 Subject: [PATCH 15/19] Refactor element retrieval and library initialization Moved element retrieval to the top and removed duplicate declarations. --- debugging/book-library/script.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 6d3cbdcc..cba44084 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,4 +1,9 @@ -let myLibrary = []; +const titleEl = document.getElementById("title"); +const authorEl = document.getElementById("author"); +const pagesEl = document.getElementById("pages"); +const checkEl = document.getElementById("check"); +const submitBtnEl = document.getElementById("submit-btn"); +const myLibrary = []; window.addEventListener("load", function (e) { populateStorage(); render(); @@ -18,12 +23,6 @@ function populateStorage() { } } -const titleEl = document.getElementById("title"); -const authorEl = document.getElementById("author"); -const pagesEl = document.getElementById("pages"); -const checkEl = document.getElementById("check"); -const submitBtnEl = document.getElementById("submit-btn"); - submitBtnEl.addEventListener("click", function (event) { event.preventDefault(); submit(); From 79887c0e35af82c2eecce419be9024b477b46916 Mon Sep 17 00:00:00 2001 From: marthak1 <60424466+marthak1@users.noreply.github.com> Date: Tue, 21 Apr 2026 19:55:51 +0100 Subject: [PATCH 16/19] Remove IDs from buttons in book library --- 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 cba44084..fd6bf584 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -94,7 +94,6 @@ function render() { //add and wait for action for read/unread button const changeBut = document.createElement("button"); - changeBut.id = i; changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); changeBut.innerText = myLibrary[i].check ? "Yes" : "No"; @@ -105,7 +104,6 @@ function render() { //add delete button to every row and render again const delBut = document.createElement("button"); - delBut.id = i + 5; deleteCell.appendChild(delBut); delBut.className = "btn btn-warning"; delBut.innerHTML = "Delete"; From a92aab76bbdedee5559b9c2ad0fc30cdda939df3 Mon Sep 17 00:00:00 2001 From: marthak1 <60424466+marthak1@users.noreply.github.com> Date: Tue, 21 Apr 2026 20:14:00 +0100 Subject: [PATCH 17/19] Refactor table row clearing in render function Replaced old table deletion method with innerHTML clearing. --- 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 fd6bf584..6de0a16b 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -75,10 +75,9 @@ function showMessage(text) { } function render() { const table = document.getElementById("display"); - //delete old table - while (table.rows.length > 1) { - table.deleteRow(1); - } + const tableBody = document.querySelector("tbody"); + tableBody.innerHTML = ""; // clears all rows +} //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { From 5cdb0e0136d21b0c5347125312b05adf2ad811d0 Mon Sep 17 00:00:00 2001 From: marthak1 <60424466+marthak1@users.noreply.github.com> Date: Tue, 21 Apr 2026 22:51:11 +0100 Subject: [PATCH 18/19] removed bracket Added missing opening brace for the render function. --- 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 6de0a16b..e6cead30 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -77,7 +77,7 @@ function render() { const table = document.getElementById("display"); const tableBody = document.querySelector("tbody"); tableBody.innerHTML = ""; // clears all rows -} + //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { From 9ddeb45054e9055f538622bd25f6f7a6d1ac3100 Mon Sep 17 00:00:00 2001 From: marthak1 <60424466+marthak1@users.noreply.github.com> Date: Tue, 21 Apr 2026 23:03:12 +0100 Subject: [PATCH 19/19] Fix row insertion to use tableBody instead of table --- 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 e6cead30..e80d6926 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -81,7 +81,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 = tableBody.insertRow(1); let titleCell = row.insertCell(0); let authorCell = row.insertCell(1); let pagesCell = row.insertCell(2);