From 5e1ba2bb8e3c1ed4f164e87bf66cf10fa2660be2 Mon Sep 17 00:00:00 2001 From: ofonimeedak Date: Wed, 15 Apr 2026 10:42:48 +0100 Subject: [PATCH 1/2] 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 23acfa71..4d8f3b62 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/2] 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 75ce6c1d..57751d4f 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();