From f435f9b1548fb06b48b5be0417c9b65fe1f29825 Mon Sep 17 00:00:00 2001 From: Segun Date: Sun, 13 Apr 2025 18:41:17 +0100 Subject: [PATCH 01/10] ClosingBracketAdded --- debugging/book-library/script.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..34da8fa2 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -6,8 +6,8 @@ window.addEventListener("load", function (e) { }); function populateStorage() { - if (myLibrary.length == 0) { - let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); + if (myLibrary.length === 0) { + let book1 = new Book("Robinson Crusoe", "Daniel Defoe", "252", true); let book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", @@ -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-- ){ //A closing bracket was missing here initially table.deleteRow(n); } //insert updated row and cells From 9b7b4d5fc3198df61d84d315ac64f5f720ca91e1 Mon Sep 17 00:00:00 2001 From: Segun Date: Sat, 19 Apr 2025 16:47:40 +0100 Subject: [PATCH 02/10] fix invalid types in HTML --- debugging/book-library/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 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 /> Date: Sat, 19 Apr 2025 21:14:41 +0100 Subject: [PATCH 03/10] identifying more errors --- debugging/book-library/script.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 34da8fa2..4c6fcaad 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -16,7 +16,7 @@ function populateStorage() { ); myLibrary.push(book1); myLibrary.push(book2); - render(); + render; } } @@ -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(); } } @@ -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 == true) { readStatus = "Yes"; } else { readStatus = "No"; @@ -91,10 +91,10 @@ function render() { //add delete button to every row and render again let delButton = document.createElement("button"); delBut.id = i + 5; - deleteCell.appendChild(delBut); + deleteCell.appendChild(delButton); delBut.className = "btn btn-warning"; delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delBut.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 3afe2b142746b7dc2680af8fe5579ab46bf9c1ee Mon Sep 17 00:00:00 2001 From: Segun Date: Sun, 20 Apr 2025 01:50:20 +0100 Subject: [PATCH 04/10] correctingMyLibraryErro --- debugging/book-library/index.html | 8 ++------ debugging/book-library/script.js | 12 ++++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 2628651d..a2cda55a 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,7 +1,7 @@ - + Library Library - - - - - + diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 4c6fcaad..dfa111e6 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -16,7 +16,7 @@ function populateStorage() { ); myLibrary.push(book1); myLibrary.push(book2); - render; + //render; } } @@ -38,7 +38,7 @@ function submit() { return false; } else { let book = new Book(title.value, author.value, pages.value, check.checked); - MyLibrary.push(book); + myLibrary.push(book); render(); } } @@ -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(delButton); - delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; - delBut.addEventListener("click", function () { + 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 efe036b076e004cbb8841bc07726c2b033830ac3 Mon Sep 17 00:00:00 2001 From: Segun Date: Sun, 20 Apr 2025 02:16:09 +0100 Subject: [PATCH 05/10] ClearEntryAfterSubmission --- debugging/book-library/script.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index dfa111e6..4b8a3aa9 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -31,8 +31,12 @@ function submit() { if ( title.value == null || title.value == "" || + author.value == null || + author.value == "" || pages.value == null || - pages.value == "" + pages.value == ""|| + check.checked == null|| + check.checked == "" ) { alert("Please fill all fields!"); return false; @@ -40,6 +44,10 @@ function submit() { let book = new Book(title.value, author.value, pages.value, check.checked); myLibrary.push(book); render(); + title.value = ""; + author.value = ""; + pages.value = ""; + check.checked = false; } } From ee12456fa04b57231c57f83822178fcb0a6b9eea Mon Sep 17 00:00:00 2001 From: Segun Date: Mon, 21 Apr 2025 01:46:07 +0100 Subject: [PATCH 06/10] Reduce repitition using the ternary operator based on feedback --- debugging/book-library/script.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 4b8a3aa9..e11bcbeb 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -34,9 +34,9 @@ function submit() { author.value == null || author.value == "" || pages.value == null || - pages.value == ""|| - check.checked == null|| - check.checked == "" + pages.value == "" + //check.checked == null|| + //check.checked == "" ) { alert("Please fill all fields!"); return false; @@ -84,11 +84,14 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == true) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } + + // if (myLibrary[i].check == true) { + // readStatus = "Yes"; + //} else { + //readStatus = "No"; + //} + readStatus = myLibrary[i].check ? "Yes" : "No"; + changeBut.innerText = readStatus; changeBut.addEventListener("click", function () { From 6c068ee720531439a76e02efca16209243e23745 Mon Sep 17 00:00:00 2001 From: Segun Date: Mon, 21 Apr 2025 02:04:00 +0100 Subject: [PATCH 07/10] Reviewing variable declarations-Used const instead of let --- debugging/book-library/script.js | 38 ++++++++++++++------------------ 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index e11bcbeb..3351a9ec 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,4 +1,4 @@ -let myLibrary = []; +const myLibrary = []; window.addEventListener("load", function (e) { populateStorage(); @@ -7,8 +7,8 @@ window.addEventListener("load", function (e) { function populateStorage() { if (myLibrary.length === 0) { - let book1 = new Book("Robinson Crusoe", "Daniel Defoe", "252", true); - let book2 = new Book( + const book1 = new Book("Robinson Crusoe", "Daniel Defoe", "252", true); + const book2 = new Book( "The Old Man and the Sea", "Ernest Hemingway", "127", @@ -41,7 +41,7 @@ function submit() { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, author.value, pages.value, check.checked); + const book = new Book(title.value, author.value, pages.value, check.checked); myLibrary.push(book); render(); title.value = ""; @@ -59,37 +59,33 @@ function Book(title, author, pages, check) { } function render() { - let table = document.getElementById("display"); - let rowsNumber = table.rows.length; + const table = document.getElementById("display"); + const rowsNumber = table.rows.length; //delete old table for (let n = rowsNumber - 1; n > 0; n-- ){ //A closing bracket was missing here initially table.deleteRow(n); } //insert updated row and cells - let length = myLibrary.length; + const length = myLibrary.length; for (let i = 0; i < length; i++) { - let row = table.insertRow(1); - 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); + const row = table.insertRow(1); + const titleCell = row.insertCell(0); + const authorCell = row.insertCell(1); + const pagesCell = row.insertCell(2); + const wasReadCell = row.insertCell(3); + const 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"); + const changeBut = document.createElement("button"); changeBut.id = i; changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); - let readStatus = ""; + const readStatus = ""; - // if (myLibrary[i].check == true) { - // readStatus = "Yes"; - //} else { - //readStatus = "No"; - //} + readStatus = myLibrary[i].check ? "Yes" : "No"; changeBut.innerText = readStatus; @@ -100,7 +96,7 @@ function render() { }); //add delete button to every row and render again - let delButton = document.createElement("button"); + const delButton = document.createElement("button"); delButton.id = i + 5; deleteCell.appendChild(delButton); delButton.className = "btn btn-warning"; From 80eddc0b9901d31e79f0c3c4c60676407b4b489d Mon Sep 17 00:00:00 2001 From: Segun Date: Mon, 21 Apr 2025 02:15:01 +0100 Subject: [PATCH 08/10] redeclaring-Replacing let with const --- 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 3351a9ec..06e08312 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -83,7 +83,7 @@ function render() { changeBut.id = i; changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); - const readStatus = ""; + let readStatus = ""; readStatus = myLibrary[i].check ? "Yes" : "No"; From 6fb76711b11caed4d777f0e193d0185e3c8c65cb Mon Sep 17 00:00:00 2001 From: Segun Date: Mon, 21 Apr 2025 02:42:14 +0100 Subject: [PATCH 09/10] Making-title,wuthor,pages and check local varaibles --- debugging/book-library/script.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 06e08312..96732ec3 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -20,14 +20,18 @@ function populateStorage() { } } + + +//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() { + const title = document.getElementById("title"); const author = document.getElementById("author"); const pages = document.getElementById("pages"); 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() { + if ( title.value == null || title.value == "" || @@ -35,8 +39,7 @@ function submit() { author.value == "" || pages.value == null || pages.value == "" - //check.checked == null|| - //check.checked == "" + ) { alert("Please fill all fields!"); return false; From d00b5d25648c15654cb21d352ab91285105f0436 Mon Sep 17 00:00:00 2001 From: Segun Date: Mon, 21 Apr 2025 02:53:29 +0100 Subject: [PATCH 10/10] SavingChanges --- debugging/book-library/script.js | 1 - 1 file changed, 1 deletion(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 96732ec3..37540a42 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -21,7 +21,6 @@ function populateStorage() { } - //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() {