From 2aa2f27286ced424361a8b361da1f54801205d1f Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Thu, 11 Dec 2025 13:35:02 +0000 Subject: [PATCH 01/12] input type = text --- 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..2628651d 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -31,7 +31,7 @@

Library

Library /> Date: Thu, 11 Dec 2025 13:47:45 +0000 Subject: [PATCH 02/12] use type=button instead of type=submit to prevent form submitting and page reloading --- debugging/book-library/index.html | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 2628651d..1749c29a 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -61,12 +61,11 @@

Library

value="" />Read - + id="submitBtn" + >Submit
From 2297934ced10cfb7e89ba981960912ae13e35fe2 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Fri, 12 Dec 2025 12:06:07 +0000 Subject: [PATCH 03/12] first draft --- debugging/book-library/script.js | 132 ++++++++++++++++--------------- 1 file changed, 70 insertions(+), 62 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..0b2ca621 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,103 +1,111 @@ let myLibrary = []; -window.addEventListener("load", function (e) { +window.addEventListener("load", function () { populateStorage(); render(); + const submitBtn = document.getElementById("submitBtn"); + submitBtn.addEventListener("click", submit); }); 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 - ); + const book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); + const book2 = new Book("The Old Man and the Sea","Ernest Hemingway","127", true); myLibrary.push(book1); myLibrary.push(book2); - render(); } } -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() { if ( - title.value == null || - title.value == "" || - pages.value == null || - pages.value == "" + titleInput.value == null || + titleInput.value == "" || + pagesInput.value == null || + pagesInput.value == "" ) { alert("Please fill all fields!"); return false; - } else { - let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); - render(); + } + if (isNaN(Number(pagesVal)) || Number(pagesVal) <= 0) { + alert("Please enter a valid number of pages!"); + return false; } + + const book = new Book(titleVal, authorVal, pagesValue, readCheckBox.checked); + myLibrary.push(book); + titleInput.value = ""; + authorInput.value = ""; + pagesInput.value = ""; + readCheckBox.checked = false; + render(); + return true; } -function Book(title, author, pages, check) { +function Book(title, author, pages, hasRead) { this.title = title; this.author = author; this.pages = pages; - this.check = check; + this.hasRead = Boolean(hasRead); } 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); + const table = document.getElementById("display"); + const tbody = table.querySelector("tbody"); + while (tbody.firstChild) { + tbody.removeChild(tbody.firstChild); } - //insert updated row and cells - let 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); - 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"); - 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; + for (let i = 0; i < myLibrary.length; i++) { + const book = myLibrary[i]; + const row = document.createElement("tr"); + + const titleCell = document.createElement("td"); + titleCell.textContent = book.title; + row.appendChild(titleCell); + const authorCell = document.createElement("td"); + authorCell.textContent = book.author; + row.appendChild(authorCell); + + const pagesCell = document.createElement("td"); + pagesCell.textContent = book.pages; + row.appendChild(pagesCell); + + const wasReadCell = document.createElement("td"); + const changeBut = document.createElement("button"); + changeBut.className = "btn btn-success"; + changeBut.textContent = book.hasRead ? "Yes" : "No"; + changeBut.dataset.index = i; changeBut.addEventListener("click", function () { - myLibrary[i].check = !myLibrary[i].check; + const index = Number(this.dataset.index); + myLibrary[index].hasRead = !myLibrary[index].hasRead; render(); }); + wasReadCell.appendChild(changeBut); + row.appendChild(wasReadCell); - //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 () { - alert(`You've deleted title: ${myLibrary[i].title}`); - myLibrary.splice(i, 1); + //delete button + const deleteCell = document.createElement("td"); + const delButton = document.createElement("button"); + delButton.className = "btn btn-warning"; + delButton.textContent = "Delete"; + delButton.dataset.index = i; + delButton.addEventListener("click", function () { + const index = Number(this.dataset.index); + alert(`You've deleted title: ${myLibrary[index].title}`); + myLibrary.splice(index, 1); render(); }); + deleteCell.appendChild(delButton); + row.appendChild(deleteCell); + + tbody.appendChild(row); } } From ca01638f61e791d6fff748aaa3809bc293a4e8c8 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Fri, 12 Dec 2025 12:08:56 +0000 Subject: [PATCH 04/12] html bug fix --- debugging/book-library/index.html | 70 ++++++++----------------------- 1 file changed, 17 insertions(+), 53 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 1749c29a..4dd8b782 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,20 +1,15 @@ - - + Library + + - - + + + @@ -30,42 +25,19 @@

Library

- + + - + + - -
@@ -79,15 +51,7 @@

Library

- - - - - - - - - + From 0b493a3c58ca845293c93df103c67450568ceeed Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Fri, 12 Dec 2025 12:09:13 +0000 Subject: [PATCH 05/12] script.js bug fixes --- debugging/book-library/script.js | 102 +++++++++++++------------------ 1 file changed, 42 insertions(+), 60 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 0b2ca621..2456842d 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -3,16 +3,13 @@ let myLibrary = []; window.addEventListener("load", function () { populateStorage(); render(); - const submitBtn = document.getElementById("submitBtn"); - submitBtn.addEventListener("click", submit); + document.getElementById("submitBtn").addEventListener("click", submit); }); function populateStorage() { - if (myLibrary.length == 0) { - const book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); - const book2 = new Book("The Old Man and the Sea","Ernest Hemingway","127", true); - myLibrary.push(book1); - myLibrary.push(book2); + if (myLibrary.length === 0) { + myLibrary.push(new Book("Robinson Crusoe", "Daniel Defoe", 252, true)); + myLibrary.push(new Book("The Old Man and the Sea", "Ernest Hemingway", 127, true)); } } @@ -21,29 +18,29 @@ 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() { - if ( - titleInput.value == null || - titleInput.value == "" || - pagesInput.value == null || - pagesInput.value == "" - ) { + const titleVal = titleInput.value.trim(); + const authorVal = authorInput.value.trim(); + const pagesVal = pagesInput.value.trim(); + + if (!titleVal || !authorVal || !pagesVal) { alert("Please fill all fields!"); return false; - } + } + if (isNaN(Number(pagesVal)) || Number(pagesVal) <= 0) { alert("Please enter a valid number of pages!"); return false; } - const book = new Book(titleVal, authorVal, pagesValue, readCheckBox.checked); + const book = new Book(titleVal, authorVal, Number(pagesVal), readCheckBox.checked); myLibrary.push(book); + titleInput.value = ""; authorInput.value = ""; pagesInput.value = ""; readCheckBox.checked = false; + render(); return true; } @@ -56,56 +53,41 @@ function Book(title, author, pages, hasRead) { } function render() { - const table = document.getElementById("display"); - const tbody = table.querySelector("tbody"); - while (tbody.firstChild) { - tbody.removeChild(tbody.firstChild); - } + const tbody = document.querySelector("#display tbody"); + tbody.innerHTML = ""; - for (let i = 0; i < myLibrary.length; i++) { - const book = myLibrary[i]; + myLibrary.forEach((book, i) => { const row = document.createElement("tr"); - const titleCell = document.createElement("td"); - titleCell.textContent = book.title; - row.appendChild(titleCell); - - const authorCell = document.createElement("td"); - authorCell.textContent = book.author; - row.appendChild(authorCell); - - const pagesCell = document.createElement("td"); - pagesCell.textContent = book.pages; - row.appendChild(pagesCell); - - const wasReadCell = document.createElement("td"); - const changeBut = document.createElement("button"); - changeBut.className = "btn btn-success"; - changeBut.textContent = book.hasRead ? "Yes" : "No"; - changeBut.dataset.index = i; - changeBut.addEventListener("click", function () { - const index = Number(this.dataset.index); - myLibrary[index].hasRead = !myLibrary[index].hasRead; + row.innerHTML = ` + ${book.title} + ${book.author} + ${book.pages} + + + `; + + const readButton = document.createElement("button"); + readButton.className = "btn btn-success"; + readButton.textContent = book.hasRead ? "Yes" : "No"; + readButton.addEventListener("click", () => { + book.hasRead = !book.hasRead; render(); }); - wasReadCell.appendChild(changeBut); - row.appendChild(wasReadCell); - - //delete button - const deleteCell = document.createElement("td"); - const delButton = document.createElement("button"); - delButton.className = "btn btn-warning"; - delButton.textContent = "Delete"; - delButton.dataset.index = i; - delButton.addEventListener("click", function () { - const index = Number(this.dataset.index); - alert(`You've deleted title: ${myLibrary[index].title}`); - myLibrary.splice(index, 1); + + row.children[3].appendChild(readButton); + + const deleteButton = document.createElement("button"); + deleteButton.className = "btn btn-warning"; + deleteButton.textContent = "Delete"; + deleteButton.addEventListener("click", () => { + alert(`You deleted: ${book.title}`); + myLibrary.splice(i, 1); render(); }); - deleteCell.appendChild(delButton); - row.appendChild(deleteCell); + + row.children[4].appendChild(deleteButton); tbody.appendChild(row); - } + }); } From 22b841f1727e879a448244ffd958f9be369b8940 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Fri, 12 Dec 2025 12:29:32 +0000 Subject: [PATCH 06/12] CSS styled for improved design and useability --- debugging/book-library/style.css | 122 ++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 12 deletions(-) diff --git a/debugging/book-library/style.css b/debugging/book-library/style.css index 302950cb..8c600c57 100644 --- a/debugging/book-library/style.css +++ b/debugging/book-library/style.css @@ -1,19 +1,117 @@ -.form-group { - width: 400px; - height: 300px; - align-self: left; - padding-left: 20px; +/* Global styles */ +body { + font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; + background: #f7f7fb; + margin: 0; + padding: 20px; } -.btn { - display: block; +/* Header */ +.jumbotron { + background: linear-gradient(135deg, #3c8dbc, #5fa7d9); + color: white; + border-radius: 12px; + padding: 40px 20px; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); } -.form-check-label { - padding-left: 20px; - margin: 5px 0px 5px 0px; +/* Main Button */ +button.btn-info { + background: #3c8dbc; + border: none; + padding: 10px 20px; + border-radius: 8px; + font-size: 16px; + transition: 0.2s; } -button.btn-info { - margin: 20px; +button.btn-info:hover { + background: #337aa5; + transform: translateY(-2px); +} + +/* Form Collapse Panel */ +#demo { + background: white; + margin-top: 20px; + padding: 20px; + border-radius: 12px; + box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08); +} + +.form-group label { + margin-top: 10px; + font-weight: 600; +} + +.form-control { + border-radius: 8px; + padding: 10px; +} + +/* Submit Button */ +#submitBtn { + margin-top: 20px; + background: #28a745; + border: none; + padding: 10px 20px; + border-radius: 10px; + font-size: 16px; + transition: 0.2s; +} + +#submitBtn:hover { + background: #218838; + transform: translateY(-2px); +} + +/* Table */ +.table { + margin-top: 40px; + background: white; + border-radius: 12px; + overflow: hidden; + box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1); +} + +.thead-dark th { + background: #3c3f46; + color: white; + border: none; +} + +/* Table Row Hover Effect */ +.table tbody tr { + transition: 0.2s; +} + +.table tbody tr:hover { + background: #f0f4ff; +} + +/* Buttons Inside Table */ +.btn-success, +.btn-warning { + font-size: 14px; + padding: 6px 12px; + border-radius: 8px; + transition: 0.2s; +} + +.btn-success:hover { + background: #1e7e34; + transform: scale(1.05); +} + +.btn-warning:hover { + background: #d39e00; + transform: scale(1.05); +} +.read-yes { + background-color: #166629; + color: white; } +.read-no { + background-color: #5c2329; + color: white; +} \ No newline at end of file From 0a6dbc1a9ef739fa0517af1f6f4fe7f1d3c44fbf Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Fri, 12 Dec 2025 12:29:48 +0000 Subject: [PATCH 07/12] Update read button styling to reflect book read status --- debugging/book-library/script.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 2456842d..b4310a4a 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -68,8 +68,13 @@ function render() { `; const readButton = document.createElement("button"); - readButton.className = "btn btn-success"; - readButton.textContent = book.hasRead ? "Yes" : "No"; + if (book.hasRead) { + readButton.className = "btn btn-success"; + readButton.textContent = "Yes"; + } else { + readButton.className = "btn btn-danger"; + readButton.textContent = "No"; + } readButton.addEventListener("click", () => { book.hasRead = !book.hasRead; render(); From 97d1213355d14b8a60faa20cae88ad88814dc590 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Fri, 12 Dec 2025 12:30:04 +0000 Subject: [PATCH 08/12] Update header title to 'My Book Library' --- 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 4dd8b782..f2bb4dcd 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -14,7 +14,7 @@
-

Library

+

My Book Library

Add books to your virtual library

From 539d8c9569009d0d126e655feff64c13887c3e86 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Fri, 12 Dec 2025 13:47:03 +0000 Subject: [PATCH 09/12] Refactor CSS comments for clarity and consistency --- debugging/book-library/style.css | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/debugging/book-library/style.css b/debugging/book-library/style.css index 8c600c57..db1096fc 100644 --- a/debugging/book-library/style.css +++ b/debugging/book-library/style.css @@ -1,4 +1,4 @@ -/* Global styles */ +/* Global Styles */ body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; background: #f7f7fb; @@ -6,7 +6,7 @@ body { padding: 20px; } -/* Header */ +/* Header / Jumbotron */ .jumbotron { background: linear-gradient(135deg, #3c8dbc, #5fa7d9); color: white; @@ -15,22 +15,22 @@ body { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); } -/* Main Button */ -button.btn-info { +/* "Add New Book" Button */ +.btn-info { background: #3c8dbc; border: none; padding: 10px 20px; border-radius: 8px; font-size: 16px; - transition: 0.2s; + transition: 0.2s ease; } -button.btn-info:hover { +.btn-info:hover { background: #337aa5; transform: translateY(-2px); } -/* Form Collapse Panel */ +/* Form Collapse Box */ #demo { background: white; margin-top: 20px; @@ -57,7 +57,7 @@ button.btn-info:hover { padding: 10px 20px; border-radius: 10px; font-size: 16px; - transition: 0.2s; + transition: 0.2s ease; } #submitBtn:hover { @@ -74,13 +74,14 @@ button.btn-info:hover { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1); } +/* Table Header */ .thead-dark th { background: #3c3f46; color: white; border: none; } -/* Table Row Hover Effect */ +/* Row Hover */ .table tbody tr { transition: 0.2s; } @@ -89,13 +90,13 @@ button.btn-info:hover { background: #f0f4ff; } -/* Buttons Inside Table */ +/* Buttons in Table */ .btn-success, .btn-warning { font-size: 14px; padding: 6px 12px; border-radius: 8px; - transition: 0.2s; + transition: 0.2s ease; } .btn-success:hover { @@ -107,11 +108,3 @@ button.btn-info:hover { background: #d39e00; transform: scale(1.05); } -.read-yes { - background-color: #166629; - color: white; -} -.read-no { - background-color: #5c2329; - color: white; -} \ No newline at end of file From 330610bf1bfdfe391cffad320f7c8439eb1081b5 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Fri, 12 Dec 2025 13:48:15 +0000 Subject: [PATCH 10/12] general feedback applied to improve book management --- debugging/book-library/script.js | 102 +++++++++++++++++++------------ 1 file changed, 64 insertions(+), 38 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index b4310a4a..1965b30e 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,62 +1,85 @@ let myLibrary = []; +class Book { + constructor(title, author, pages, hasRead) { + this.title = title; + this.author = author; + this.pages = pages; + this.hasRead = Boolean(hasRead); + } +} -window.addEventListener("load", function () { - populateStorage(); - render(); - document.getElementById("submitBtn").addEventListener("click", submit); +// Initial Setup +window.addEventListener("load", () => { + seedInitialBooks(); + renderLibrary(); + document.getElementById("submitBtn").addEventListener("click", handleSubmit); }); -function populateStorage() { +// Add starter books if library is empty +function seedInitialBooks() { if (myLibrary.length === 0) { myLibrary.push(new Book("Robinson Crusoe", "Daniel Defoe", 252, true)); myLibrary.push(new Book("The Old Man and the Sea", "Ernest Hemingway", 127, true)); } } +// Form Inputs const titleInput = document.getElementById("title"); const authorInput = document.getElementById("author"); const pagesInput = document.getElementById("pages"); const readCheckBox = document.getElementById("check"); -function submit() { +// Form Submission +function handleSubmit() { const titleVal = titleInput.value.trim(); const authorVal = authorInput.value.trim(); const pagesVal = pagesInput.value.trim(); - if (!titleVal || !authorVal || !pagesVal) { + if (!validateInputs(titleVal, authorVal, pagesVal)) return; + + const newBook = new Book( + titleVal, + authorVal, + Number(pagesVal), + readCheckBox.checked + ); + + myLibrary.push(newBook); + resetForm(); + renderLibrary(); +} + +// Validate input values +function validateInputs(title, author, pages) { + if (!title || !author || !pages) { alert("Please fill all fields!"); return false; } - if (isNaN(Number(pagesVal)) || Number(pagesVal) <= 0) { + const pagesNum = Number(pages); + + if (isNaN(pagesNum) || pagesNum <= 0) { alert("Please enter a valid number of pages!"); return false; } - const book = new Book(titleVal, authorVal, Number(pagesVal), readCheckBox.checked); - myLibrary.push(book); + return true; +} +// Clear form after successful submission +function resetForm() { titleInput.value = ""; authorInput.value = ""; pagesInput.value = ""; readCheckBox.checked = false; - - render(); - return true; -} - -function Book(title, author, pages, hasRead) { - this.title = title; - this.author = author; - this.pages = pages; - this.hasRead = Boolean(hasRead); } -function render() { +// Rendering +function renderLibrary() { const tbody = document.querySelector("#display tbody"); tbody.innerHTML = ""; - myLibrary.forEach((book, i) => { + myLibrary.forEach((book, index) => { const row = document.createElement("tr"); row.innerHTML = ` @@ -67,32 +90,35 @@ function render() { `; + // Read Button const readButton = document.createElement("button"); - if (book.hasRead) { - readButton.className = "btn btn-success"; - readButton.textContent = "Yes"; - } else { - readButton.className = "btn btn-danger"; - readButton.textContent = "No"; - } - readButton.addEventListener("click", () => { - book.hasRead = !book.hasRead; - render(); - }); + readButton.textContent = book.hasRead ? "Yes" : "No"; + readButton.className = book.hasRead ? "btn btn-success" : "btn btn-danger"; + readButton.addEventListener("click", () => toggleReadStatus(index)); row.children[3].appendChild(readButton); + // Delete Button const deleteButton = document.createElement("button"); deleteButton.className = "btn btn-warning"; deleteButton.textContent = "Delete"; - deleteButton.addEventListener("click", () => { - alert(`You deleted: ${book.title}`); - myLibrary.splice(i, 1); - render(); - }); + deleteButton.addEventListener("click", () => deleteBook(index)); row.children[4].appendChild(deleteButton); tbody.appendChild(row); }); } + +// Toggle read/unread status +function toggleReadStatus(index) { + myLibrary[index].hasRead = !myLibrary[index].hasRead; + renderLibrary(); +} + +// Delete a book from the library +function deleteBook(index) { + alert(`You deleted: ${myLibrary[index].title}`); + myLibrary.splice(index, 1); + renderLibrary(); +} From 385e9d058e91b7eb4f03ded38f3503bd101adb1c Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Fri, 12 Dec 2025 13:48:52 +0000 Subject: [PATCH 11/12] general feedback applied to improve html structure --- debugging/book-library/index.html | 67 +++++++++++++++++-------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index f2bb4dcd..b1758ec3 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,8 +1,9 @@ - Library - + Book Library + + @@ -18,42 +19,48 @@

My Book Library

Add books to your virtual library

- +
-
-
- - + - - +
+
- - + + - + + - + + + + + + +
-
- - - - - - - - - - - -
TitleAuthorNumber of PagesRead
+ + + + + + + + + + + +
TitleAuthorNumber of PagesRead
+ +
+ From 921f47a6d5c4fe9e6cd7df242bdf0e0331de7620 Mon Sep 17 00:00:00 2001 From: zilinskyte Date: Mon, 15 Dec 2025 02:10:45 +0000 Subject: [PATCH 12/12] feedback addressed --- debugging/book-library/script.js | 37 +++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 1965b30e..77e28fa2 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -58,7 +58,7 @@ function validateInputs(title, author, pages) { const pagesNum = Number(pages); - if (isNaN(pagesNum) || pagesNum <= 0) { + if (!Number.isInteger(pagesNum) || pagesNum <= 0) { alert("Please enter a valid number of pages!"); return false; } @@ -82,13 +82,23 @@ function renderLibrary() { myLibrary.forEach((book, index) => { const row = document.createElement("tr"); - row.innerHTML = ` - ${book.title} - ${book.author} - ${book.pages} - - - `; + const titleCell = document.createElement("td"); + titleCell.textContent = book.title; + row.appendChild(titleCell); + + const authorCell = document.createElement("td"); + authorCell.textContent = book.author; + row.appendChild(authorCell); + + const pagesCell = document.createElement("td"); + pagesCell.textContent = book.pages; + row.appendChild(pagesCell); + + const readCell = document.createElement("td"); + row.appendChild(readCell); + + const deleteCell = document.createElement("td"); + row.appendChild(deleteCell); // Read Button const readButton = document.createElement("button"); @@ -118,7 +128,10 @@ function toggleReadStatus(index) { // Delete a book from the library function deleteBook(index) { - alert(`You deleted: ${myLibrary[index].title}`); - myLibrary.splice(index, 1); - renderLibrary(); -} +const confirmed = confirm( `Are you sure you want to delete "${myLibrary[index].title}"?` ); +if (!confirmed) return; +const deletedBook = myLibrary[index].title; +myLibrary.splice(index, 1); +renderLibrary(); +alert(`"${deletedBook}" has been deleted from your library.`); +} \ No newline at end of file