From 0b6299ae07593cbd2251fadd8b07bac7d58d601e Mon Sep 17 00:00:00 2001 From: Hendrine Zeraua Date: Wed, 13 Aug 2025 20:57:13 +0100 Subject: [PATCH 01/12] fix(seed): correct title typo and store pages as numbers --- 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 75ce6c1d..2427e59f 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -7,13 +7,13 @@ 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( - "The Old Man and the Sea", - "Ernest Hemingway", - "127", - true - ); + let book1 = new Book("Robinson Crusoe", "Daniel Defoe", 252, true); + let book2 = new Book( + "The Old Man and the Sea", + "Ernest Hemingway", + 127, + true +); myLibrary.push(book1); myLibrary.push(book2); render(); From 6d9d84a19fcd00a567d1a461d8fbd428a97a5d81 Mon Sep 17 00:00:00 2001 From: Hendrine Zeraua Date: Wed, 13 Aug 2025 21:01:46 +0100 Subject: [PATCH 02/12] fix(add): use author field and push to myLibrary --- 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 2427e59f..31302a41 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -37,8 +37,8 @@ function submit() { 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(); } } From 0b088a8806f8e0743eea5ca439289ddfa1a1ce4e Mon Sep 17 00:00:00 2001 From: Hendrine Zeraua Date: Wed, 13 Aug 2025 21:23:48 +0100 Subject: [PATCH 03/12] feat(validate): require author and enforce pages as positive integer" --- debugging/book-library/script.js | 33 ++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 31302a41..035010b5 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -25,22 +25,35 @@ const author = document.getElementById("author"); const pages = document.getElementById("pages"); 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 == "" + !title.value?.trim() || + !author.value?.trim() || + !pages.value?.trim() ) { alert("Please fill all fields!"); return false; - } else { - let book = new Book(title.value, author.value, pages.value, check.checked); - myLibrary.push(book); - render(); } + + const pagesNum = Number(pages.value); + if (!Number.isInteger(pagesNum) || pagesNum < 1) { + alert("Pages must be a positive whole number."); + return false; + } + + // create and add the book + const book = new Book( + title.value.trim(), + author.value.trim(), + pagesNum, + check.checked + ); + myLibrary.push(book); + render(); + return true; +} } function Book(title, author, pages, check) { From feee60674e0a0b7f2b637ad7b37d1339ecded1e8 Mon Sep 17 00:00:00 2001 From: Hendrine Zeraua Date: Wed, 13 Aug 2025 21:54:38 +0100 Subject: [PATCH 04/12] fix(render): correct table-clearing loop syntax --- 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 035010b5..816cc638 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -66,8 +66,8 @@ 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-- { + + for (let n = rowsNumber - 1; n > 0; n--) { table.deleteRow(n); } //insert updated row and cells From 1966aacd8e25c6bfb30dc5dac3f2c7679637cfbf Mon Sep 17 00:00:00 2001 From: Hendrine Zeraua Date: Wed, 13 Aug 2025 22:21:15 +0100 Subject: [PATCH 05/12] fix(delete): correct variable name and event type so delete button works --- 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 816cc638..4c406e67 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -101,16 +101,16 @@ function render() { render(); }); - //add delete button to every row and render again - let delButton = document.createElement("button"); - delBut.id = i + 5; - deleteCell.appendChild(delBut); + const delBut = document.createElement("button"); + delBut.id = String(i + 5); delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delBut.textContent = "Delete"; + delBut.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); - }); +}); +deleteCell.appendChild(delBut); } } + From 790c614e7954174a3adcb8db9d0f9773aa6ee460 Mon Sep 17 00:00:00 2001 From: Hendrine Zeraua Date: Wed, 13 Aug 2025 22:35:56 +0100 Subject: [PATCH 06/12] fix(read-status): show 'Yes' when checked and 'No' when unchecked --- debugging/book-library/script.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 4c406e67..918a105d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -88,13 +88,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.textContent = myLibrary[i].check ? "Yes" : "No"; changeBut.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check; From bd070c0452cad45029cf2225c974da66275510b4 Mon Sep 17 00:00:00 2001 From: Hendrine Zeraua Date: Wed, 13 Aug 2025 22:57:01 +0100 Subject: [PATCH 07/12] use textContent instead of innerHTML for table cells --- 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 918a105d..1efda7cb 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -79,9 +79,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 = String(myLibrary[i].pages); //add and wait for action for read/unread button let changeBut = document.createElement("button"); From d8c315efc4c33d9044b68d9a1fefbcbd95bd851e Mon Sep 17 00:00:00 2001 From: Hendrine Zeraua Date: Wed, 13 Aug 2025 23:20:08 +0100 Subject: [PATCH 08/12] clear form fields after adding a book --- debugging/book-library/script.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 1efda7cb..57da1512 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -43,7 +43,6 @@ function submit() { return false; } - // create and add the book const book = new Book( title.value.trim(), author.value.trim(), @@ -52,9 +51,15 @@ function submit() { ); myLibrary.push(book); render(); + + + title.value = ""; + author.value = ""; + pages.value = ""; + check.checked = false; + return true; } -} function Book(title, author, pages, check) { this.title = title; @@ -70,7 +75,7 @@ function render() { 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++) { let row = table.insertRow(1); @@ -83,7 +88,7 @@ function render() { authorCell.textContent = myLibrary[i].author; pagesCell.textContent = String(myLibrary[i].pages); - //add and wait for action for read/unread button + let changeBut = document.createElement("button"); changeBut.id = i; changeBut.className = "btn btn-success"; From 43ed85fc90c84f595cd2153293fd00b0e73c63da Mon Sep 17 00:00:00 2001 From: Hendrine Zeraua Date: Wed, 13 Aug 2025 23:39:24 +0100 Subject: [PATCH 09/12] set proper title, split meta tags, and constrain pages input --- debugging/book-library/index.html | 144 ++++++++++++------------------ 1 file changed, 57 insertions(+), 87 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..307fb9bc 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,96 +1,66 @@ - - - - - - - - - - -
-

Library

-

Add books to your virtual library

-
+ + Library + + + + + + + + + - + +
+

Library

+

Add books to your virtual library

+
-
-
- - - - - - - - -
+ + +
+
+ + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + +
TitleAuthorNumber of PagesRead
- - - - - - - - - - - - - - - - - - - -
TitleAuthorNumber of PagesRead
+ + - - From 3197a2bb2d316fb07fb25c99daa3708cbafef60a Mon Sep 17 00:00:00 2001 From: Hendrine Zeraua Date: Wed, 13 Aug 2025 23:51:19 +0100 Subject: [PATCH 10/12] fix input types and remove placeholder table row --- debugging/book-library/index.html | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 307fb9bc..525389a2 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -26,9 +26,9 @@

Library

- + - + @@ -49,15 +49,7 @@

Library

- - - - - - - - - + From 558b5259b76ac8a6561ed2021c6e10decbbd98a1 Mon Sep 17 00:00:00 2001 From: Hendrine Zeraua Date: Wed, 13 Aug 2025 23:57:30 +0100 Subject: [PATCH 11/12] use button for submit since there is no form element --- 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 525389a2..a07a481c 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -35,7 +35,7 @@

Library

- +
From 75de4c4f8a45a96732ffc5ec413b9bcfc51ca4d4 Mon Sep 17 00:00:00 2001 From: Hendrine Zeraua Date: Thu, 14 Aug 2025 21:35:01 +0100 Subject: [PATCH 12/12] refactor: apply reviewer feedback for performance, clarity, and UX improvements --- debugging/book-library/script.js | 59 +++++++++++--------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 57da1512..3a7e84a3 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,19 +1,14 @@ let myLibrary = []; -window.addEventListener("load", function (e) { +window.addEventListener("load", function () { populateStorage(); render(); }); function populateStorage() { - if (myLibrary.length == 0) { - let book1 = new Book("Robinson Crusoe", "Daniel Defoe", 252, true); - let book2 = new Book( - "The Old Man and the Sea", - "Ernest Hemingway", - 127, - true -); + if (myLibrary.length === 0) { + let book1 = new Book("Robinson Crusoe", "Daniel Defoe", 252, true); + let book2 = new Book("The Old Man and the Sea", "Ernest Hemingway", 127, true); myLibrary.push(book1); myLibrary.push(book2); render(); @@ -25,39 +20,31 @@ const author = document.getElementById("author"); const pages = document.getElementById("pages"); const check = document.getElementById("check"); - function submit() { - - if ( - !title.value?.trim() || - !author.value?.trim() || - !pages.value?.trim() - ) { + const titleInput = title.value.trim(); + const authorInput = author.value.trim(); + const pagesInput = pages.value.trim(); + const pagesNum = Number(pagesInput); + + if (!titleInput || !authorInput || !pagesInput) { alert("Please fill all fields!"); return false; } - const pagesNum = Number(pages.value); if (!Number.isInteger(pagesNum) || pagesNum < 1) { alert("Pages must be a positive whole number."); return false; } - const book = new Book( - title.value.trim(), - author.value.trim(), - pagesNum, - check.checked - ); + const book = new Book(titleInput, authorInput, pagesNum, check.checked); myLibrary.push(book); render(); - - + title.value = ""; author.value = ""; pages.value = ""; check.checked = false; - + return true; } @@ -70,11 +57,7 @@ function Book(title, author, pages, check) { function render() { let table = document.getElementById("display"); - let rowsNumber = table.rows.length; - - for (let n = rowsNumber - 1; n > 0; n--) { - table.deleteRow(n); - } + table.querySelector("tbody").innerHTML = ""; let length = myLibrary.length; for (let i = 0; i < length; i++) { @@ -88,13 +71,10 @@ function render() { authorCell.textContent = myLibrary[i].author; pagesCell.textContent = String(myLibrary[i].pages); - let changeBut = document.createElement("button"); - changeBut.id = i; changeBut.className = "btn btn-success"; - wasReadCell.appendChild(changeBut); - changeBut.textContent = myLibrary[i].check ? "Yes" : "No"; + wasReadCell.appendChild(changeBut); changeBut.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check; @@ -102,15 +82,16 @@ function render() { }); const delBut = document.createElement("button"); - delBut.id = String(i + 5); delBut.className = "btn btn-warning"; delBut.textContent = "Delete"; + deleteCell.appendChild(delBut); + delBut.addEventListener("click", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); + const deletedTitle = myLibrary[i].title; myLibrary.splice(i, 1); render(); -}); -deleteCell.appendChild(delBut); + alert(`You've deleted title: ${deletedTitle}`); + }); } }