From 469c440f156f821d6e06049128fe6561d07c5720 Mon Sep 17 00:00:00 2001 From: Aida Zhukova Date: Wed, 16 Apr 2025 16:35:46 +0100 Subject: [PATCH 1/4] all bugs have been fixed --- debugging/book-library/script.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..09cb565b 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -31,14 +31,16 @@ function submit() { if ( title.value == null || title.value == "" || - pages.value == null || - pages.value == "" + pages.value == null || + 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(); } } @@ -53,8 +55,10 @@ function Book(title, author, pages, check) { function render() { let table = document.getElementById("display"); let rowsNumber = table.rows.length; + console.log(myLibrary) + //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 +80,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"; @@ -90,11 +94,11 @@ 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 + 5; + 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 e3e0407498a05a926d18d3519ae442ec514a245a Mon Sep 17 00:00:00 2001 From: Aida Zhukova Date: Thu, 17 Apr 2025 23:24:30 +0100 Subject: [PATCH 2/4] addressed Pr comments --- debugging/book-library/index.html | 14 +++++------ debugging/book-library/script.js | 42 +++++++++++++------------------ 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..7b93ad85 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,12 +1,9 @@ - - + Book Library + + @@ -31,7 +28,7 @@

Library

Library /> Library class="form-control" id="pages" name="pages" + min="1" required />