From 7d232c0b30bd69986da7eba27d9ef89da542a19b Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sun, 19 Jan 2025 19:33:59 +0000 Subject: [PATCH 01/10] missing for loop brackets on line 57, added --- debugging/book-library/script.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..8fb849e9 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -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; + delButton.id = i + 5; deleteCell.appendChild(delBut); - delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + 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 883602315befdc1eb4e720f3557c5ab5bf240a0f Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sun, 19 Jan 2025 19:48:28 +0000 Subject: [PATCH 02/10] changed let for const to create the new button --- debugging/book-library/script.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 8fb849e9..eed706fd 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -90,11 +90,11 @@ function render() { //add delete button to every row and render again let delButton = document.createElement("button"); - delButton.id = i + 5; + delBut.id = i + 5; deleteCell.appendChild(delBut); - delButton.className = "btn btn-warning"; - delButton.innerHTML = "Delete"; - delButton.addEventListener("clicks", function () { + delBut.className = "btn btn-warning"; + delBut.innerHTML = "Delete"; + delBut.addEventListener("clicks", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 6688f1bc106aaf48f925ce02725750151c8dc6cb Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sun, 19 Jan 2025 19:49:37 +0000 Subject: [PATCH 03/10] bug with declaration of variable fixed with delButton --- debugging/book-library/script.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index eed706fd..b620f0f9 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -7,7 +7,7 @@ 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("Robinson Crusoe", "Daniel Defoe", "252", true); let book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", @@ -37,8 +37,8 @@ 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); + let book = new Book(title.value, author.value, pages.value, check.checked); + myLibrary.push(book); render(); } } @@ -89,12 +89,12 @@ 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 () { + const delButton = document.createElement("button"); + 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 d20badadca7767c176f5df289fa35c7a072c9689 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sun, 19 Jan 2025 20:15:32 +0000 Subject: [PATCH 04/10] fixed bug incorrect name event, clicks instead "click" and passing as parameter index directly in the event to avoid overlapping, delButton eventListener --- debugging/book-library/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index b620f0f9..277a95d5 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -94,9 +94,9 @@ function render() { deleteCell.appendChild(delButton); delButton.className = "btn btn-warning"; delButton.innerHTML = "Delete"; - delButton.addEventListener("clicks", function () { + delButton.addEventListener("click", function (index) { alert(`You've deleted title: ${myLibrary[i].title}`); - myLibrary.splice(i, 1); + myLibrary.splice(index, 1); render(); }); } From 86d7c9747fcf1481d105354bc393256ab275e729 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sun, 19 Jan 2025 20:35:40 +0000 Subject: [PATCH 05/10] fixed boolean comparision to false == "No" --- debugging/book-library/script.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 277a95d5..a3715e8a 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -76,10 +76,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; @@ -88,6 +88,29 @@ function render() { render(); }); + + // second option to booleans comparisons + // let changeBut = document.createElement("button"); + // changeBut.id = i; + // changeBut.className = "btn btn-success"; + // wasReadCell.appendChild(changeBut); + // let readStatus = ""; + + // // Directly check for boolean value (true or false) + // if (myLibrary[i].check == false) { + // readStatus = "No"; + // } else { + // readStatus = "Yes"; + // } + + // changeBut.innerText = readStatus; + + // changeBut.addEventListener("click", function () { + // myLibrary[i].check = !myLibrary[i].check; // Toggle the read status + // render(); + // }); + + //add delete button to every row and render again const delButton = document.createElement("button"); delButton.id = i + 5; From 784e45dc3628e62a5601a9deece6e38aa0ecd329 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sun, 19 Jan 2025 20:35:40 +0000 Subject: [PATCH 06/10] fixed boolean comparision to false == "No" --- debugging/book-library/script.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..9b920a7f 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -76,10 +76,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; @@ -88,6 +88,29 @@ function render() { render(); }); + + // second option to booleans comparisons + // let changeBut = document.createElement("button"); + // changeBut.id = i; + // changeBut.className = "btn btn-success"; + // wasReadCell.appendChild(changeBut); + // let readStatus = ""; + + // // Directly check for boolean value (true or false) + // if (myLibrary[i].check == false) { + // readStatus = "No"; + // } else { + // readStatus = "Yes"; + // } + + // changeBut.innerText = readStatus; + + // changeBut.addEventListener("click", function () { + // myLibrary[i].check = !myLibrary[i].check; // Toggle the read status + // render(); + // }); + + //add delete button to every row and render again let delButton = document.createElement("button"); delBut.id = i + 5; From 86531092064272c879d9ee7034b68f1a801a7a75 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sun, 19 Jan 2025 20:15:32 +0000 Subject: [PATCH 07/10] fixed bug incorrect name event, clicks instead "click" and passing as parameter index directly in the event to avoid overlapping, delButton eventListener --- 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 9b920a7f..425b60a2 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -112,14 +112,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 () { + const delButton = document.createElement("button"); + delButton.id = i + 5; + deleteCell.appendChild(delButton); + delButton.className = "btn btn-warning"; + delButton.innerHTML = "Delete"; + delButton.addEventListener("click", function (index) { alert(`You've deleted title: ${myLibrary[i].title}`); - myLibrary.splice(i, 1); + myLibrary.splice(index, 1); render(); }); } From b5f00c7104b0b5637bd64efa9c2a477f0a7dfe75 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Sun, 19 Jan 2025 21:56:27 +0000 Subject: [PATCH 08/10] tested ok --- debugging/book-library/script.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index a3715e8a..6b970063 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -76,7 +76,7 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == "false") { + if (myLibrary[i].check == false) { readStatus = "No"; } else { readStatus = "Yes"; @@ -88,8 +88,7 @@ function render() { render(); }); - - // second option to booleans comparisons + // // second option to booleans comparisons // let changeBut = document.createElement("button"); // changeBut.id = i; // changeBut.className = "btn btn-success"; @@ -110,16 +109,15 @@ function render() { // render(); // }); - //add delete button to every row and render again const delButton = document.createElement("button"); delButton.id = i + 5; deleteCell.appendChild(delButton); delButton.className = "btn btn-warning"; delButton.innerHTML = "Delete"; - delButton.addEventListener("click", function (index) { + delButton.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); - myLibrary.splice(index, 1); + myLibrary.splice(i, 1); render(); }); } From 323fbf6ec5710ce45548f47fe6832c903d818ef2 Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 20 Jan 2025 01:27:09 +0000 Subject: [PATCH 09/10] fix the user to type negative number and decimal values. --- debugging/book-library/script.js | 36 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 6b970063..cf8f6f1b 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(); }); @@ -14,9 +14,8 @@ function populateStorage() { "127", true ); - myLibrary.push(book1); + myLibrary.push(book1); myLibrary.push(book2); - render(); } } @@ -31,10 +30,14 @@ function submit() { if ( title.value == null || title.value == "" || + author.value == null || + author.value == "" || pages.value == null || - pages.value == "" + pages.value == "" || + pages.value <= 0 || + pages.value != parseInt() ) { - alert("Please fill all fields!"); + alert("Please fill with valid input!"); return false; } else { let book = new Book(title.value, author.value, pages.value, check.checked); @@ -71,19 +74,19 @@ 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 = ""; 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(); }); @@ -110,12 +113,11 @@ function render() { // }); //add delete button to every row and render again - const delButton = document.createElement("button"); - delButton.id = i + 5; - deleteCell.appendChild(delButton); - delButton.className = "btn btn-warning"; - delButton.innerHTML = "Delete"; - delButton.addEventListener("click", function () { + const deleteButton = document.createElement("button"); + deleteCell.appendChild(deleteButton); + deleteButton.className = "btn btn-warning"; + deleteButton.innerHTML = "Delete"; + deleteButton.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 7ef843a8e7a1bb45ffcfb5efaaf0da17ad84a61c Mon Sep 17 00:00:00 2001 From: "Karla G." Date: Mon, 20 Jan 2025 01:40:23 +0000 Subject: [PATCH 10/10] adapted the alert message to prevent to deleted it. --- 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 cf8f6f1b..ed7d298f 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -118,7 +118,7 @@ function render() { deleteButton.className = "btn btn-warning"; deleteButton.innerHTML = "Delete"; deleteButton.addEventListener("click", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); + alert(`You are deleting: "${myLibrary[i].title}" Are you sure?!`); myLibrary.splice(i, 1); render(); });