From 895f5a1474a68b86222e3736bbc6950bb3838866 Mon Sep 17 00:00:00 2001 From: RihannaP <114884466+RihannaP@users.noreply.github.com> Date: Sun, 12 Jan 2025 01:47:04 +0000 Subject: [PATCH 1/2] Fix bugs in book adding, deleting, and read status functionality --- debugging/book-library/script.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1..f47569f 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,6 +1,6 @@ let myLibrary = []; -window.addEventListener("load", function (e) { +window.addEventListener("load", function () { populateStorage(); render(); }); @@ -37,8 +37,10 @@ function submit() { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); + //Correctly pass author.value + let book = new Book(title.value, author.value, pages.value, check.checked); + //Replace library.push(book) with myLibrary.push(book) + myLibrary.push(book); render(); } } @@ -54,7 +56,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 @@ -76,7 +78,8 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == false) { + //Fix the logic for the "Read" statues true for "Yes", false for No + if (myLibrary[i].check == true) { readStatus = "Yes"; } else { readStatus = "No"; @@ -89,12 +92,14 @@ function render() { }); //add delete button to every row and render again + // correct delButton in rows 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"; + //Fix the event listener: "click" instead of "clicks". + delButton.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 474c094365ddaaf2014ea79824cbaeedfd6d97fc Mon Sep 17 00:00:00 2001 From: RihannaP <114884466+RihannaP@users.noreply.github.com> Date: Mon, 13 Jan 2025 05:12:11 +0000 Subject: [PATCH 2/2] fixing reviews --- debugging/book-library/script.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index f47569f..bc25906 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -31,6 +31,8 @@ function submit() { if ( title.value == null || title.value == "" || + author.value == null || + author.value == "" || pages.value == null || pages.value == "" ) { @@ -73,10 +75,10 @@ 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 = ""; //Fix the logic for the "Read" statues true for "Yes", false for No if (myLibrary[i].check == true) { @@ -84,9 +86,9 @@ function render() { } else { readStatus = "No"; } - changeBut.innerText = readStatus; + changeButton.innerText = readStatus; - changeBut.addEventListener("click", function () { + changeButton.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check; render(); }); @@ -94,7 +96,7 @@ function render() { //add delete button to every row and render again // correct delButton in rows let delButton = document.createElement("button"); - delButton.id = i + 5; + //delButton.id = i + 5; deleteCell.appendChild(delButton); delButton.className = "btn btn-warning"; delButton.innerHTML = "Delete";