From ff9566240cd365f95eef4c2071420979a770ccad Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Mon, 13 Apr 2026 16:01:50 +0100 Subject: [PATCH 01/13] Refactored code to provide list of books --- 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..a7646b04 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 @@ -94,7 +94,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(); From 332b11fde9fd7f84961e8ce911c0dae8dd0fcc46 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Mon, 13 Apr 2026 16:06:38 +0100 Subject: [PATCH 02/13] Refactored code to enable books to be added, author field updates correctly, read lables match checkbox update, delete button handels correctly --- debugging/book-library/script.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index a7646b04..01cec616 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -31,14 +31,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(); } } @@ -76,7 +78,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 +92,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("click", 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 d539435664d84ce347a27978cc8bd8dea8b2b8df Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Tue, 14 Apr 2026 14:28:59 +0100 Subject: [PATCH 03/13] Refactored code using validator w3 to check --- debugging/book-library/index.html | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..beb9b430 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,12 +1,10 @@ - - + + - - + Book Library + + + @@ -65,7 +63,7 @@

Library

type="submit" value="Submit" class="btn btn-primary" - onclick="submit();" + onclick="submit()" /> From be162d89a549d1477ac77b867adc9209eafb2de7 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Tue, 14 Apr 2026 14:39:09 +0100 Subject: [PATCH 04/13] Refactored code using validator w3 to check --- debugging/book-library/index.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index beb9b430..ec2a54cf 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -26,10 +26,11 @@

Library

+ // form to add new book
- + // input for book title Library /> Date: Tue, 14 Apr 2026 14:49:45 +0100 Subject: [PATCH 05/13] Refactored code as per CJ Update --- debugging/book-library/index.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index ec2a54cf..0d30297d 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -32,6 +32,7 @@

Library

Library Library Library - + From a46d75463bd06804b349071de17932622df29432 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Tue, 14 Apr 2026 14:55:00 +0100 Subject: [PATCH 06/13] Refactored code to only call render once on page load and remove unused load event parameter --- debugging/book-library/script.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 01cec616..e8d2118a 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(); }); @@ -16,7 +16,6 @@ function populateStorage() { ); myLibrary.push(book1); myLibrary.push(book2); - render(); } } From 633689d1f8e993a6977e3802a576f7397bd3ff93 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Wed, 15 Apr 2026 14:52:50 +0100 Subject: [PATCH 07/13] Refactored code to update as per https://github.com/CodeYourFuture/Module-Data-Flows/blob/general-review-feedback/debugging/book-library/feedback.md --- debugging/book-library/index.html | 11 +++--- debugging/book-library/script.js | 56 +++++++++++++++++-------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 0d30297d..aff4ca0a 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -32,7 +32,8 @@

Library

Library Library Library - + diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index e8d2118a..055f7776 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -19,26 +19,35 @@ 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() { - if ( - title.value == null || - title.value == "" || - author.value == null || - author.value == "" || - pages.value == null || - pages.value == "" - ) { - alert("Please fill all fields!"); + const title = titleInput.value.trim(); + const author = authorInput.value.trim(); + const pages = pagesInput.valueAsNumber; + + if (!title) { + alert("Please enter a valid title."); + return false; + } + + if (!author) { + alert("Please enter a valid author."); + return false; + } + + if (!Number.isInteger(rawPages) || rawPages <= 0) { + alert("Please enter a valid page number."); return false; } else { - let book = new Book(title.value, author.value, pages.value, check.checked); + titleInput.value = title; + authorInput.value = author; + let book = new Book(title, author, pages, checkInput.checked); myLibrary.push(book); render(); } @@ -76,12 +85,7 @@ function render() { changeBut.id = i; changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); - let readStatus = ""; - if (myLibrary[i].check == true) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } + let readStatus = myLibrary[i].check == true ? "Yes" : "No"; changeBut.innerText = readStatus; changeBut.addEventListener("click", function () { @@ -90,12 +94,12 @@ 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"; - delButton.addEventListener("click", function () { + let deleteBut = document.createElement("button"); + deleteBut.id = i + 5; + deleteCell.appendChild(deleteBut); + deleteBut.className = "btn btn-warning"; + deleteBut.innerHTML = "Delete"; + deleteBut.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 0d32deb78b2f6f5ffa9b1ab7ee1f6f21e6e5803f Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Wed, 15 Apr 2026 14:56:29 +0100 Subject: [PATCH 08/13] Refactored code to update as per https://github.com/CodeYourFuture/Module-Data-Flows/blob/general-review-feedback/debugging/book-library/feedback.md --- debugging/book-library/script.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 055f7776..ae8fc99b 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -7,8 +7,8 @@ window.addEventListener("load", function () { 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", @@ -61,31 +61,31 @@ function Book(title, author, pages, check) { } function render() { - let table = document.getElementById("display"); - let rowsNumber = table.rows.length; + const table = document.getElementById("display"); + const rowsNumber = table.rows.length; //delete old table for (let n = rowsNumber - 1; n > 0; n--) { table.deleteRow(n); } //insert updated row and cells - let length = myLibrary.length; + const length = myLibrary.length; for (let i = 0; i < length; i++) { - let row = table.insertRow(1); - let titleCell = row.insertCell(0); - let authorCell = row.insertCell(1); - let pagesCell = row.insertCell(2); - let wasReadCell = row.insertCell(3); - let deleteCell = row.insertCell(4); + const row = table.insertRow(1); + const titleCell = row.insertCell(0); + const authorCell = row.insertCell(1); + const pagesCell = row.insertCell(2); + const wasReadCell = row.insertCell(3); + const deleteCell = row.insertCell(4); titleCell.innerHTML = myLibrary[i].title; authorCell.innerHTML = myLibrary[i].author; pagesCell.innerHTML = 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 = myLibrary[i].check == true ? "Yes" : "No"; + const readStatus = myLibrary[i].check == true ? "Yes" : "No"; changeBut.innerText = readStatus; changeBut.addEventListener("click", function () { @@ -94,14 +94,15 @@ function render() { }); //add delete button to every row and render again - let deleteBut = document.createElement("button"); + const deleteBut = document.createElement("button"); deleteBut.id = i + 5; deleteCell.appendChild(deleteBut); deleteBut.className = "btn btn-warning"; deleteBut.innerHTML = "Delete"; deleteBut.addEventListener("click", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); + const deletedTitle = myLibrary[i].title; myLibrary.splice(i, 1); + alert(`You've deleted title: ${deletedTitle}`); render(); }); } From 41d2fe6d8e9848adf0b55b022479f460a1c47702 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Thu, 16 Apr 2026 12:22:51 +0100 Subject: [PATCH 09/13] changed the page constraint from maxlength to max so limmiting no. of pages to 10000 --- 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 aff4ca0a..f14d486b 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -53,7 +53,7 @@

Library

type="number" class="form-control" min="1" - maxlength="10000" + max="10000" id="pages" name="pages" required From f3c310d029dfa86dfa0830e3cfc198eaabe24e05 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Thu, 16 Apr 2026 12:29:47 +0100 Subject: [PATCH 10/13] changed the let Library=[] to Const --- 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 ae8fc99b..73637964 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 59f4052bc61de2e24b139e1667baf5d278c6c0e5 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Thu, 16 Apr 2026 12:32:16 +0100 Subject: [PATCH 11/13] changed the page length from string to number --- 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 73637964..acc4a1d3 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -7,11 +7,11 @@ window.addEventListener("load", function () { function populateStorage() { if (myLibrary.length == 0) { - const book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); + const book1 = new Book("Robison Crusoe", "Daniel Defoe", 252, true); const book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", - "127", + 127, true ); myLibrary.push(book1); @@ -41,7 +41,7 @@ function submit() { return false; } - if (!Number.isInteger(rawPages) || rawPages <= 0) { + if (!Number.isInteger(pages) || pages <= 0) { alert("Please enter a valid page number."); return false; } else { From f1f4ebc5d0a211b6047d7f6f07360968790cbe86 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Thu, 16 Apr 2026 12:44:58 +0100 Subject: [PATCH 12/13] changed use of .innerHTML to textContent --- debugging/book-library/script.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index acc4a1d3..255bd950 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -76,9 +76,9 @@ function render() { const pagesCell = row.insertCell(2); const wasReadCell = row.insertCell(3); const 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 const changeBut = document.createElement("button"); @@ -98,7 +98,7 @@ function render() { deleteBut.id = i + 5; deleteCell.appendChild(deleteBut); deleteBut.className = "btn btn-warning"; - deleteBut.innerHTML = "Delete"; + deleteBut.textContent = "Delete"; deleteBut.addEventListener("click", function () { const deletedTitle = myLibrary[i].title; myLibrary.splice(i, 1); From bfb4558e2a2f484c8f617c925c59822130ab291a Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Thu, 16 Apr 2026 12:57:22 +0100 Subject: [PATCH 13/13] removed unused but ids --- 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 255bd950..6bdf2ef9 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -82,7 +82,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); const readStatus = myLibrary[i].check == true ? "Yes" : "No"; @@ -95,7 +94,6 @@ function render() { //add delete button to every row and render again const deleteBut = document.createElement("button"); - deleteBut.id = i + 5; deleteCell.appendChild(deleteBut); deleteBut.className = "btn btn-warning"; deleteBut.textContent = "Delete";