From 5e4bb132bf5b98bace53948cf723741d8be50d8f Mon Sep 17 00:00:00 2001 From: asaniDev Date: Tue, 16 Dec 2025 22:39:27 +0000 Subject: [PATCH 1/9] fixed delete button element to be at the end of each row. --- 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..340b2006 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, author.value, pages.value, check.checked); library.push(book); 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 @@ -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 66ca3f478767cb414d3f88401ab47f68151e752a Mon Sep 17 00:00:00 2001 From: asaniDev Date: Tue, 16 Dec 2025 22:46:58 +0000 Subject: [PATCH 2/9] fixed function to add a new book to the library --- 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 340b2006..33b90d8d 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, author.value, pages.value, check.checked); - library.push(book); + myLibrary.push(book); render(); } } From a0ca64d797b2db4717ab02c5ef2cf408c35c4c3a Mon Sep 17 00:00:00 2001 From: asaniDev Date: Tue, 16 Dec 2025 22:50:46 +0000 Subject: [PATCH 3/9] fixed delete button so a row is deleted when button clicked --- 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 33b90d8d..90f038e6 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 20dbaefca323e1fc574a5bc0aa7f9ac3a1090624 Mon Sep 17 00:00:00 2001 From: asaniDev Date: Tue, 16 Dec 2025 23:12:55 +0000 Subject: [PATCH 4/9] removed the render function from load event since its called in populateStorage --- debugging/book-library/readme.md | 10 +++++----- debugging/book-library/script.js | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/debugging/book-library/readme.md b/debugging/book-library/readme.md index 3abe8c13..70b3cce4 100644 --- a/debugging/book-library/readme.md +++ b/debugging/book-library/readme.md @@ -12,11 +12,11 @@ My website should be able to: ## 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 +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 + I think there are other some other small bugs in my code...but I'm lazy so I can't fix them all. diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 90f038e6..a17d3a8e 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() { @@ -76,10 +75,10 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { + if (myLibrary[i].check === false) { readStatus = "No"; + } else { + readStatus = "Yes"; } changeBut.innerText = readStatus; From d9e3fa56b3fcc78c488ff77a49a3787311198fba Mon Sep 17 00:00:00 2001 From: asaniDev Date: Tue, 16 Dec 2025 23:32:17 +0000 Subject: [PATCH 5/9] changed input type for title and author to text --- debugging/book-library/script.js | 1 + 1 file changed, 1 insertion(+) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index a17d3a8e..c9133a1b 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -27,6 +27,7 @@ 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() { + console.log(title.value, author.value, pages.value, check.value) if ( title.value == null || title.value == "" || From a53ccc16b4c88fcf2b7089ceaf672de5c2609fe3 Mon Sep 17 00:00:00 2001 From: asaniDev Date: Tue, 16 Dec 2025 23:53:44 +0000 Subject: [PATCH 6/9] added checks for author field and negative values for page number --- debugging/book-library/index.html | 4 ++-- debugging/book-library/script.js | 7 +++---- 2 files changed, 5 insertions(+), 6 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 /> add the new book (object in array) //via Book function and start render function function submit() { - console.log(title.value, author.value, pages.value, check.value) if ( - title.value == null || title.value == "" || - pages.value == null || - pages.value == "" + author.value == "" || + pages.value == ""|| + pages.value <= 0 ) { alert("Please fill all fields!"); return false; From 9fcdbe72e6e313e5d00e8ee3d1b519905f81a0b3 Mon Sep 17 00:00:00 2001 From: asaniDev Date: Sun, 21 Dec 2025 08:21:21 +0000 Subject: [PATCH 7/9] used the feedback improvement guide to check other errors i might have missed, and fixed those errors. --- debugging/book-library/index.html | 19 ++++----- debugging/book-library/script.js | 71 +++++++++++++++++++------------ debugging/book-library/style.css | 2 +- 3 files changed, 53 insertions(+), 39 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 2628651d..ce34e02b 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,20 +1,19 @@ - + - + Book Library App + + > - + > + @@ -65,8 +64,8 @@

Library

type="submit" value="Submit" class="btn btn-primary" - onclick="submit();" - /> + id = "submitButton" + >
@@ -91,6 +90,6 @@

Library

- + diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 4fd2eaee..3df33c89 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -19,29 +19,42 @@ function populateStorage() { } } -const title = document.getElementById("title"); -const author = document.getElementById("author"); -const pages = document.getElementById("pages"); -const check = document.getElementById("check"); +const titleElem = document.getElementById("title"); +const authorElem = document.getElementById("author"); +const pagesElem = document.getElementById("pages"); +const checkBox = 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 == "" || - author.value == "" || - pages.value == ""|| - pages.value <= 0 +export function submit() { + + if (!Number.isInteger(Number(pagesElem.value))){ + alert("Pages must be an integer !"); + return false; + } + else if ( + titleElem.value.trim() == "" || + authorElem.value.trim() == "" || + pagesElem.value == ""|| + pagesElem.value <= 0 ) { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, author.value, pages.value, check.checked); + let book = new Book(titleElem.value.toString().trim(), authorElem.value.trim(), Number(pagesElem.value), checkBox.checked); myLibrary.push(book); render(); + titleElem.value = ""; + authorElem.value = ""; + pagesElem.value = ""; + checkBox.checked = false; } } +document.querySelector('#submitButton').addEventListener('click', () => { + submit(); +}) + function Book(title, author, pages, check) { this.title = title; this.author = author; @@ -51,38 +64,37 @@ 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); - } + let tableBody = document.querySelector('tbody'); + + tableBody.innerHTML = ""; + //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(0); 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; + titleCell.innerText = myLibrary[i].title; + authorCell.innerText = myLibrary[i].author; + pagesCell.innerText = 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(); }); @@ -92,11 +104,14 @@ function render() { delButton.id = i + 5; deleteCell.appendChild(delButton); delButton.className = "btn btn-warning"; - delButton.innerHTML = "Delete"; + delButton.innerText = "Delete"; delButton.addEventListener("click", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); + const deletedTitle = myLibrary[i].title; myLibrary.splice(i, 1); render(); + setTimeout(() => { + alert(`You've deleted title: ${deletedTitle}`); + }, 0) }); } } diff --git a/debugging/book-library/style.css b/debugging/book-library/style.css index 302950cb..3da9f9cb 100644 --- a/debugging/book-library/style.css +++ b/debugging/book-library/style.css @@ -1,7 +1,7 @@ .form-group { width: 400px; height: 300px; - align-self: left; + align-self: start; padding-left: 20px; } From 1b6e5104a1d3b9f2eb3328ffea1731faa7def8e6 Mon Sep 17 00:00:00 2001 From: asaniDev Date: Mon, 22 Dec 2025 12:02:02 +0000 Subject: [PATCH 8/9] used variables to store sanitised input values, added a ternary operator romved unnecessary id's --- debugging/book-library/index.html | 14 ++++++-------- debugging/book-library/script.js | 32 +++++++++++++++---------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index ce34e02b..fbcd0ef7 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -31,32 +31,30 @@

Library

diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 3df33c89..ef3fe5fc 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); @@ -19,29 +19,32 @@ function populateStorage() { } } -const titleElem = document.getElementById("title"); -const authorElem = document.getElementById("author"); -const pagesElem = document.getElementById("pages"); -const checkBox = document.getElementById("check"); +const titleElem = document.querySelector(".title"); +const authorElem = document.querySelector(".author"); +const pagesElem = document.querySelector(".pages"); +const checkBox = document.querySelector(".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 export function submit() { + const bookTitle = titleElem.value.toString().trim(); + const bookAuthor = authorElem.value.toString().trim(); + const bookPages = Number(pagesElem.value); if (!Number.isInteger(Number(pagesElem.value))){ alert("Pages must be an integer !"); return false; } else if ( - titleElem.value.trim() == "" || - authorElem.value.trim() == "" || - pagesElem.value == ""|| - pagesElem.value <= 0 + bookTitle == "" || + bookAuthor == "" || + bookPages == ""|| + bookPages <= 0 ) { alert("Please fill all fields!"); return false; } else { - let book = new Book(titleElem.value.toString().trim(), authorElem.value.trim(), Number(pagesElem.value), checkBox.checked); + let book = new Book(bookTitle, bookAuthor, bookPages, checkBox.checked); myLibrary.push(book); render(); titleElem.value = ""; @@ -87,11 +90,8 @@ function render() { changeButton.className = "btn btn-success"; wasReadCell.appendChild(changeButton); let readStatus = ""; - if (myLibrary[i].check === false) { - readStatus = "No"; - } else { - readStatus = "Yes"; - } + readStatus = myLibrary[i].check ? "yes":"no"; + changeButton.innerText = readStatus; changeButton.addEventListener("click", function () { From 5f990087aca2284525a8493feb6bc997dcad6de5 Mon Sep 17 00:00:00 2001 From: asaniDev Date: Mon, 22 Dec 2025 18:18:34 +0000 Subject: [PATCH 9/9] fixed bookPages variable to use for sanitising input, removed bookpagesstring comparison --- 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 ef3fe5fc..0e43be5f 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -27,18 +27,17 @@ const checkBox = document.querySelector(".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 export function submit() { - const bookTitle = titleElem.value.toString().trim(); - const bookAuthor = authorElem.value.toString().trim(); + const bookTitle = titleElem.value.trim(); + const bookAuthor = authorElem.value.trim(); const bookPages = Number(pagesElem.value); - if (!Number.isInteger(Number(pagesElem.value))){ + if (!Number.isInteger(bookPages)){ alert("Pages must be an integer !"); return false; } else if ( bookTitle == "" || bookAuthor == "" || - bookPages == ""|| bookPages <= 0 ) { alert("Please fill all fields!");