From 026ab7c7bb9aec2b0e5d5eada2359fe80ed571e2 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 20:31:55 +0100
Subject: [PATCH 01/30] Fix: Corrected variable name from 'library' to
'myLibrary' in submit 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 75ce6c1d..c5ca647c 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -38,7 +38,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();
}
}
From ba1e8fcff1da93af4c8e85839d2cd278d911362f Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 20:32:31 +0100
Subject: [PATCH 02/30] Fix: Corrected syntax error in the render function's
for loop
---
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 c5ca647c..51a8c1cb 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
From 9152461ebca6e35f15fbed4652d51bdbdb64eda0 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 20:36:47 +0100
Subject: [PATCH 03/30] Fix: Corrected button creation and event listener for
delete functionality in render function
---
debugging/book-library/script.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js
index 51a8c1cb..e4adc6a1 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -90,11 +90,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("clicks", function () {
+ delButton.id = i + 5;
+ deleteCell.appendChild(delButton);
+ delButton.className = "btn btn-warning";
+ delButton.innerHTML = "Delete";
+ delButton.addEventListener("clicks", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
From 2be93827b4353261b9e55304d86fdd77bb318303 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 20:48:17 +0100
Subject: [PATCH 04/30] Fix: Corrected validation check for author input in
submit 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 e4adc6a1..1cc1fd86 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -30,7 +30,7 @@ const check = document.getElementById("check");
function submit() {
if (
title.value == null ||
- title.value == "" ||
+ author.value == "" ||
pages.value == null ||
pages.value == ""
) {
From 2ce8154a63472d61a8de72f14c2d147b3ec9d553 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 20:52:14 +0100
Subject: [PATCH 05/30] Fix: Corrected logic for book read status in submit
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 1cc1fd86..539373fe 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -37,7 +37,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, title.value, pages.value, check.unchecked);
myLibrary.push(book);
render();
}
From e16034147fd91f306e4e55fbf5264773cad1d54e Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 20:54:18 +0100
Subject: [PATCH 06/30] Fix: Corrected event listener type for delete button in
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 539373fe..7e1e1448 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -94,7 +94,7 @@ function render() {
deleteCell.appendChild(delButton);
delButton.className = "btn btn-warning";
delButton.innerHTML = "Delete";
- delButton.addEventListener("clicks", function () {
+ delButton.addEventListener("click", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
From 62672c3540c49d759f52aafcb5631b9dbcb5f7f7 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 20:57:40 +0100
Subject: [PATCH 07/30] Fix: Corrected author value assignment in book creation
within submit 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 7e1e1448..ead55c3c 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -37,7 +37,7 @@ function submit() {
alert("Please fill all fields!");
return false;
} else {
- let book = new Book(title.value, title.value, pages.value, check.unchecked);
+ let book = new Book(title.value, author.value, pages.value, check.unchecked);
myLibrary.push(book);
render();
}
From 31236b174a25f0c1ee7d5255880f88d2c03b81e0 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 21:00:44 +0100
Subject: [PATCH 08/30] Fix: Corrected book creation to use checked state for
read status in submit 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 ead55c3c..1cd7ab99 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -37,7 +37,7 @@ function submit() {
alert("Please fill all fields!");
return false;
} else {
- let book = new Book(title.value, author.value, pages.value, check.unchecked);
+ let book = new Book(title.value, author.value, pages.value, check.checked);
myLibrary.push(book);
render();
}
From 88c944dd54fda620dbeb9f35e85c92c08738b129 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 21:02:05 +0100
Subject: [PATCH 09/30] Fix: Corrected read status display logic in render
function
---
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 1cd7ab99..8697cb5b 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -77,9 +77,9 @@ function render() {
wasReadCell.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
- readStatus = "Yes";
- } else {
readStatus = "No";
+ } else {
+ readStatus = "Yes";
}
changeBut.innerText = readStatus;
From e9a419f0fc383f188a149d65a086b131026077dd Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 21:08:41 +0100
Subject: [PATCH 10/30] Fix: Added validation for pages input in submit
function
---
debugging/book-library/script.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js
index 8697cb5b..4bbc0660 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -32,7 +32,9 @@ function submit() {
title.value == null ||
author.value == "" ||
pages.value == null ||
- pages.value == ""
+ pages.value == "" ||
+ pages.value < 0 ||
+ !Number.isInteger(pages.value)
) {
alert("Please fill all fields!");
return false;
From 9e5e0156f5b990e7e4bfbb9bf1d2f045e7d81e14 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 21:30:48 +0100
Subject: [PATCH 11/30] Fix: Added language attribute to html tag and updated
title in index.html
---
debugging/book-library/index.html | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html
index 23acfa71..85e45139 100644
--- a/debugging/book-library/index.html
+++ b/debugging/book-library/index.html
@@ -1,7 +1,7 @@
-
+
-
+ Book Library
Date: Mon, 6 Apr 2026 21:33:55 +0100
Subject: [PATCH 12/30] Fix: Standardized HTML syntax and formatting in
index.html
---
debugging/book-library/index.html | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html
index 85e45139..4e43e105 100644
--- a/debugging/book-library/index.html
+++ b/debugging/book-library/index.html
@@ -1,12 +1,10 @@
-
+
- Book Library
-
+ Book Library
+
+
+
@@ -65,7 +63,7 @@ Library
type="submit"
value="Submit"
class="btn btn-primary"
- onclick="submit();"
+ onclick="submit()"
/>
From cc880b125dcadc8d77aac4b557ca3d2fd1069ba7 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 21:36:51 +0100
Subject: [PATCH 13/30] delete trailing slash
---
debugging/book-library/index.html | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html
index 4e43e105..df289fb9 100644
--- a/debugging/book-library/index.html
+++ b/debugging/book-library/index.html
@@ -2,17 +2,16 @@
Book Library
-
-
-
+
+
+
-
+ href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
+
From 0a0dcf38eeebc87e28d53bd0e40f0c39d4658077 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Mon, 6 Apr 2026 21:41:06 +0100
Subject: [PATCH 14/30] Fix: Corrected input types for title and author fields
in index.html
---
debugging/book-library/index.html | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html
index df289fb9..ece52b67 100644
--- a/debugging/book-library/index.html
+++ b/debugging/book-library/index.html
@@ -28,7 +28,7 @@ Library
Library
/>
Date: Thu, 9 Apr 2026 15:11:23 +0100
Subject: [PATCH 15/30] Fix: Corrected meta tag and input element syntax in
index.html
---
debugging/book-library/index.html | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html
index ece52b67..56b0018b 100644
--- a/debugging/book-library/index.html
+++ b/debugging/book-library/index.html
@@ -3,8 +3,7 @@
Book Library
-
-
+
@@ -33,7 +32,7 @@ Library
id="title"
name="title"
required
- />
+ >
Library
id="author"
name="author"
required
- />
+ >
Library
id="pages"
name="pages"
required
- />
+ >
+ >
From 02d14fc06a1c3c5f3292682aa0a5ca9ef329e9f9 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Thu, 9 Apr 2026 15:27:32 +0100
Subject: [PATCH 16/30] Fix: Removed unnecessary align-self property from
.form-group in style.css
---
debugging/book-library/style.css | 1 -
1 file changed, 1 deletion(-)
diff --git a/debugging/book-library/style.css b/debugging/book-library/style.css
index 302950cb..39ce176f 100644
--- a/debugging/book-library/style.css
+++ b/debugging/book-library/style.css
@@ -1,7 +1,6 @@
.form-group {
width: 400px;
height: 300px;
- align-self: left;
padding-left: 20px;
}
From ca4167df692e27bde4865370e10adce8f4cc5bf4 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Thu, 9 Apr 2026 16:34:34 +0100
Subject: [PATCH 17/30] Fix: Corrected self-closing tags and standardized HTML
syntax in index.html
---
debugging/book-library/index.html | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html
index 56b0018b..2a3873be 100644
--- a/debugging/book-library/index.html
+++ b/debugging/book-library/index.html
@@ -2,15 +2,16 @@
Book Library
-
-
+
+
-
+ href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
+ />
+
@@ -32,7 +33,7 @@ Library
id="title"
name="title"
required
- >
+ />
Library
id="author"
name="author"
required
- >
+ />
Library
id="pages"
name="pages"
required
- >
+ />
+ />
From 866e22388fe4e32eddd91e55a21deca5a04b4518 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 08:42:54 +0100
Subject: [PATCH 18/30] Fix: Remove unnecessary render call on window load and
clean up whitespace in script.js
---
debugging/book-library/script.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js
index 4bbc0660..57f4a9ea 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -2,7 +2,6 @@ let myLibrary = [];
window.addEventListener("load", function (e) {
populateStorage();
- render();
});
function populateStorage() {
@@ -54,7 +53,10 @@ 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);
From b4fe64c702575e55ecf69299c5f1eaccda17f9ee Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 10:19:44 +0100
Subject: [PATCH 19/30] set time delay for alert message
---
debugging/book-library/script.js | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js
index 57f4a9ea..4b27f66f 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -53,10 +53,9 @@ 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);
@@ -99,9 +98,12 @@ function render() {
delButton.className = "btn btn-warning";
delButton.innerHTML = "Delete";
delButton.addEventListener("click", function () {
- alert(`You've deleted title: ${myLibrary[i].title}`);
+ const deletedTitle = myLibrary[i].title;
myLibrary.splice(i, 1);
render();
+ setTimeout(function () {
+ alert(`You've deleted title: ${deletedTitle}`);
+ }, 0);
});
}
}
From 3c8c70498af38457a87662a11621727c631bc9b1 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 10:23:51 +0100
Subject: [PATCH 20/30] Rename button variables for clarity
---
debugging/book-library/script.js | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js
index 4b27f66f..d1efa441 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -74,36 +74,36 @@ function render() {
pagesCell.innerHTML = 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";
- wasReadCell.appendChild(changeBut);
+ let changeButton = document.createElement("button");
+ changeButton.id = i;
+ changeButton.className = "btn btn-success";
+ wasReadCell.appendChild(changeButton);
let readStatus = "";
if (myLibrary[i].check == false) {
readStatus = "No";
} else {
readStatus = "Yes";
}
- changeBut.innerText = readStatus;
+ changeButton.innerText = readStatus;
- changeBut.addEventListener("click", function () {
+ changeButton.addEventListener("click", function () {
myLibrary[i].check = !myLibrary[i].check;
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 deleteButton = document.createElement("button");
+ deleteButton.id = i + 5;
+ deleteCell.appendChild(deleteButton);
+ deleteButton.className = "btn btn-warning";
+ deleteButton.innerHTML = "Delete";
+ deleteButton.addEventListener("click", function () {
const deletedTitle = myLibrary[i].title;
myLibrary.splice(i, 1);
render();
setTimeout(function () {
alert(`You've deleted title: ${deletedTitle}`);
- }, 0);
+ }, 500);
});
}
}
From e9452d64e04f69bb2d3a02833e14da8ccd6dc1d1 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 10:31:45 +0100
Subject: [PATCH 21/30] Fix: Remove unnecessary IDs from buttons in render
function
---
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 d1efa441..190f22c7 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -75,7 +75,6 @@ function render() {
//add and wait for action for read/unread button
let changeButton = document.createElement("button");
- changeButton.id = i;
changeButton.className = "btn btn-success";
wasReadCell.appendChild(changeButton);
let readStatus = "";
@@ -93,7 +92,6 @@ function render() {
//add delete button to every row and render again
let deleteButton = document.createElement("button");
- deleteButton.id = i + 5;
deleteCell.appendChild(deleteButton);
deleteButton.className = "btn btn-warning";
deleteButton.innerHTML = "Delete";
From e2af0f5d8be00ed37e3d150a0dee6d22edfc3193 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 14:33:18 +0100
Subject: [PATCH 22/30] Fix: Replace innerHTML with textContent for safer DOM
manipulation in render function
---
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 190f22c7..64ad934b 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -69,9 +69,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 changeButton = document.createElement("button");
@@ -94,7 +94,7 @@ function render() {
let deleteButton = document.createElement("button");
deleteCell.appendChild(deleteButton);
deleteButton.className = "btn btn-warning";
- deleteButton.innerHTML = "Delete";
+ deleteButton.textContent = "Delete";
deleteButton.addEventListener("click", function () {
const deletedTitle = myLibrary[i].title;
myLibrary.splice(i, 1);
From f72d53573d3a41ee0a351a6745081ae1bda5124f Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 15:03:36 +0100
Subject: [PATCH 23/30] Fix: Update validation checks in submit function for
better input handling
---
debugging/book-library/script.js | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js
index 64ad934b..c5f757a7 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -28,12 +28,11 @@ const check = document.getElementById("check");
//via Book function and start render function
function submit() {
if (
- title.value == null ||
+ title.value == "" ||
author.value == "" ||
- pages.value == null ||
pages.value == "" ||
pages.value < 0 ||
- !Number.isInteger(pages.value)
+ !Number.isInteger(+pages.value)
) {
alert("Please fill all fields!");
return false;
From 07a2811a0cc4cc19ddd4cbe0042ee13fc1f41160 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 15:13:44 +0100
Subject: [PATCH 24/30] Fix: Refactor render function to use tbody for better
DOM manipulation and update button text handling
---
debugging/book-library/script.js | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js
index c5f757a7..6ee93e83 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -51,18 +51,13 @@ function Book(title, author, pages, check) {
}
function render() {
- let table = document.getElementById("display");
+ let tableBody = document.querySelector("tbody");
+ tableBody.innerHTML = "";
- let 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;
for (let i = 0; i < length; i++) {
- let row = table.insertRow(1);
+ let row = tableBody.insertRow();
let titleCell = row.insertCell(0);
let authorCell = row.insertCell(1);
let pagesCell = row.insertCell(2);
@@ -82,7 +77,7 @@ function render() {
} else {
readStatus = "Yes";
}
- changeButton.innerText = readStatus;
+ changeButton.textContent = readStatus;
changeButton.addEventListener("click", function () {
myLibrary[i].check = !myLibrary[i].check;
From f24b3b1d56fb5688abf44ef93293e58f49eb5a05 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 15:17:57 +0100
Subject: [PATCH 25/30] Fix: Refactor submit function to use trimmed values for
better input validation
---
debugging/book-library/script.js | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js
index 6ee93e83..031fa9af 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -27,17 +27,21 @@ 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 titleValue = title.value.trim();
+ const authorValue = author.value.trim();
+ const pagesValue = pages.value.trim();
+
if (
- title.value == "" ||
- author.value == "" ||
- pages.value == "" ||
- pages.value < 0 ||
- !Number.isInteger(+pages.value)
+ titleValue == "" ||
+ authorValue == "" ||
+ pagesValue == "" ||
+ +pagesValue < 0 ||
+ !Number.isInteger(+pagesValue)
) {
alert("Please fill all fields!");
return false;
} else {
- let book = new Book(title.value, author.value, pages.value, check.checked);
+ let book = new Book(titleValue, authorValue, pagesValue, check.checked);
myLibrary.push(book);
render();
}
From c0410cca2b7900db429dfa2970cc412b9bd04988 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 15:21:37 +0100
Subject: [PATCH 26/30] Fix: Update pages value handling in submit function for
improved input validation
---
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 031fa9af..d0016cf8 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -29,14 +29,14 @@ const check = document.getElementById("check");
function submit() {
const titleValue = title.value.trim();
const authorValue = author.value.trim();
- const pagesValue = pages.value.trim();
+ const pagesValue = +pages.value.trim();
if (
titleValue == "" ||
authorValue == "" ||
pagesValue == "" ||
- +pagesValue < 0 ||
- !Number.isInteger(+pagesValue)
+ pagesValue < 0 ||
+ !Number.isInteger(pagesValue)
) {
alert("Please fill all fields!");
return false;
From 71af8ec0fd67ae47e20837bfcdd2d45b840ef5ce Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 15:27:00 +0100
Subject: [PATCH 27/30] Fix: Rename input variable references for consistency
and clarity in submit function
---
debugging/book-library/script.js | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js
index d0016cf8..71de9b26 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -19,17 +19,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 readCheckbox = 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 titleValue = title.value.trim();
- const authorValue = author.value.trim();
- const pagesValue = +pages.value.trim();
+ const titleValue = titleInput.value.trim();
+ const authorValue = authorInput.value.trim();
+ const pagesValue = +pagesInput.value.trim();
if (
titleValue == "" ||
@@ -41,7 +41,12 @@ function submit() {
alert("Please fill all fields!");
return false;
} else {
- let book = new Book(titleValue, authorValue, pagesValue, check.checked);
+ let book = new Book(
+ titleValue,
+ authorValue,
+ pagesValue,
+ readCheckbox.checked
+ );
myLibrary.push(book);
render();
}
From fff5df542ca63c3bfdf5c1c78dea239ea1b144b0 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 15:30:27 +0100
Subject: [PATCH 28/30] Fix: Correct pages value type in Book instantiation and
update validation checks in submit function
---
debugging/book-library/script.js | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js
index 71de9b26..1b9740bb 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);
@@ -29,14 +29,15 @@ const readCheckbox = document.getElementById("check");
function submit() {
const titleValue = titleInput.value.trim();
const authorValue = authorInput.value.trim();
- const pagesValue = +pagesInput.value.trim();
+ const pagesValue = pagesInput.value.trim();
+ const pagesCount = Number(pagesValue);
if (
titleValue == "" ||
authorValue == "" ||
pagesValue == "" ||
- pagesValue < 0 ||
- !Number.isInteger(pagesValue)
+ pagesCount < 0 ||
+ !Number.isInteger(pagesCount)
) {
alert("Please fill all fields!");
return false;
@@ -44,7 +45,7 @@ function submit() {
let book = new Book(
titleValue,
authorValue,
- pagesValue,
+ pagesCount,
readCheckbox.checked
);
myLibrary.push(book);
From 0e1d107a8d5e364335b55b768fbffa39ced5ce44 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 19:57:54 +0100
Subject: [PATCH 29/30] Fix: Change myLibrary to const and move input variable
declarations to the top for better organization
---
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 1b9740bb..5605d594 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -1,5 +1,8 @@
-let myLibrary = [];
-
+const myLibrary = [];
+const titleInput = document.getElementById("title");
+const authorInput = document.getElementById("author");
+const pagesInput = document.getElementById("pages");
+const readCheckbox = document.getElementById("check");
window.addEventListener("load", function (e) {
populateStorage();
});
@@ -19,10 +22,7 @@ function populateStorage() {
}
}
-const titleInput = document.getElementById("title");
-const authorInput = document.getElementById("author");
-const pagesInput = document.getElementById("pages");
-const readCheckbox = 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
From 6f8c1932239586d18621e6e6aac80d073e74cac3 Mon Sep 17 00:00:00 2001
From: alexandru-pocovnicu
<109530683+alexandru-pocovnicu@users.noreply.github.com>
Date: Fri, 17 Apr 2026 20:01:11 +0100
Subject: [PATCH 30/30] change if statement with ternary operator
---
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 5605d594..fb7760d7 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -22,8 +22,6 @@ function populateStorage() {
}
}
-
-
//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() {
@@ -82,11 +80,8 @@ function render() {
changeButton.className = "btn btn-success";
wasReadCell.appendChild(changeButton);
let readStatus = "";
- if (myLibrary[i].check == false) {
- readStatus = "No";
- } else {
- readStatus = "Yes";
- }
+
+ myLibrary[i].check == false ? (readStatus = "No") : (readStatus = "Yes");
changeButton.textContent = readStatus;
changeButton.addEventListener("click", function () {