From 5e1ba2bb8e3c1ed4f164e87bf66cf10fa2660be2 Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Wed, 15 Apr 2026 10:42:48 +0100 Subject: [PATCH 1/5] edit title and submit input button --- debugging/book-library/index.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71e..4d8f3b62b 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,7 +1,7 @@ - + - + Book Library Library type="submit" value="Submit" class="btn btn-primary" - onclick="submit();" + id="submit" /> @@ -91,6 +91,6 @@

Library

- + From dc5090c56b3fe57ed7a2493a98f2ee8ba3b6db01 Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Wed, 15 Apr 2026 10:43:31 +0100 Subject: [PATCH 2/5] debug code following criteria --- debugging/book-library/script.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d3..57751d4f4 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -2,7 +2,7 @@ let myLibrary = []; window.addEventListener("load", function (e) { populateStorage(); - render(); + //render(); }); function populateStorage() { @@ -32,17 +32,22 @@ function submit() { title.value == null || title.value == "" || pages.value == null || - pages.value == "" + pages.value == "" || + author.value == null || + author.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(); } } +const submitInput = document.getElementById("submit"); +submitInput.addEventListener("click", submit); + function Book(title, author, pages, check) { this.title = title; this.author = author; @@ -54,7 +59,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 >= 1; n--) { table.deleteRow(n); } //insert updated row and cells @@ -76,11 +81,12 @@ 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"; } + changeBut.innerText = readStatus; changeBut.addEventListener("click", function () { @@ -89,12 +95,14 @@ 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; + + 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 6bbd07a376424ed929369092c8964cd6c7d8b12a Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Sat, 18 Apr 2026 22:45:49 +0100 Subject: [PATCH 3/5] debug html and validate --- debugging/book-library/index.html | 33 ++++++------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 4d8f3b62b..446e74d1d 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,12 +1,8 @@ - + Book Library - + @@ -30,35 +26,18 @@

Library

- + - + - + Date: Sat, 18 Apr 2026 22:46:33 +0100 Subject: [PATCH 4/5] debug validate input and variable names --- debugging/book-library/script.js | 77 +++++++++++++++++--------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 57751d4f4..836fe02d4 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -20,26 +20,36 @@ function populateStorage() { } } -const title = document.getElementById("title"); -const author = document.getElementById("author"); -const pages = document.getElementById("pages"); -const check = document.getElementById("check"); +const bookTitle = document.getElementById("title"); +const authorOfBook = document.getElementById("author"); +const NoOfpages = document.getElementById("pages"); +const readBook = 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 == "" || - author.value == null || - author.value == "" + bookTitle.value.trim() === "" || + NoOfpages.value.trim() === "" || + authorOfBook.value.trim() === "" ) { alert("Please fill all fields!"); return false; + } + + if ( + !/^[A-Za-z\s]+$/.test(authorOfBook.value) || + !/^[A-Za-z\s]+$/.test(bookTitle.value) + ) { + alert("Author and book title must contain only letters"); + return false; } else { - let book = new Book(title.value, author.value, pages.value, check.checked); + let book = new Book( + bookTitle.value, + authorOfBook.value, + NoOfpages.value, + readBook.checked + ); myLibrary.push(book); render(); } @@ -48,11 +58,11 @@ function submit() { const submitInput = document.getElementById("submit"); submitInput.addEventListener("click", submit); -function Book(title, author, pages, check) { - this.title = title; - this.author = author; - this.pages = pages; - this.check = check; +function Book(bookTitle, authorOfBook, NoOfpages, readBook) { + this.bookTitle = bookTitle; + this.authorOfBook = authorOfBook; + this.NoOfpages = NoOfpages; + this.readBook = readBook; } function render() { @@ -71,39 +81,34 @@ 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; - - //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 == true) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } + titleCell.innerHTML = myLibrary[i].bookTitle; + authorCell.innerHTML = myLibrary[i].authorOfBook; + pagesCell.innerHTML = myLibrary[i].NoOfpages; - changeBut.innerText = readStatus; + let changeBtn = document.createElement("button"); + changeBtn.id = i; + changeBtn.className = "btn btn-success"; + wasReadCell.appendChild(changeBtn); + changeBtn.textContent = myLibrary[i].readBook ? "Yes" : "No"; - changeBut.addEventListener("click", function () { - myLibrary[i].check = !myLibrary[i].check; + changeBtn.addEventListener("click", function () { + myLibrary[i].readBook = !myLibrary[i].readBook; render(); }); //add delete button to every row and render again let delButton = document.createElement("button"); - delButton.id = i; + //delButton.id = i; deleteCell.appendChild(delButton); delButton.className = "btn btn-warning"; delButton.innerHTML = "Delete"; delButton.addEventListener("click", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); + const toast = document.createElement("div"); + toast.textContent = `You've deleted title: ${myLibrary[i].bookTitle}`; + table.appendChild(toast); + setTimeout(() => toast.remove(), 2000); myLibrary.splice(i, 1); render(); }); From e40e3281434f8481be15e6fff4e61b486770de12 Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Sun, 19 Apr 2026 16:19:35 +0100 Subject: [PATCH 5/5] Add input validation and decriptive variable name --- debugging/book-library/index.html | 4 +- debugging/book-library/script.js | 99 ++++++++++++++----------------- 2 files changed, 47 insertions(+), 56 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 446e74d1d..d01cf980c 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -26,9 +26,9 @@

Library

- + - +