diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..26f537f8 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -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); + //fix: change title.value to author.value + let book = new Book(title.value, author.value, pages.value, check.checked); + //Fix: change library.push(book) to myLibrary.push(book). + myLibrary.push(book); render(); } } @@ -54,7 +56,9 @@ function render() { let table = document.getElementById("display"); let rowsNumber = table.rows.length; //delete old table - for (let n = rowsNumber - 1; n > 0; n-- { + // Fix : add a ) to the end of the for loop condition + // to avoid syntax error. + for (let n = rowsNumber - 1; n > 0; n--) { table.deleteRow(n); } //insert updated row and cells @@ -76,7 +80,9 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == false) { + // Fix: change myLibrary[i].check to myLibrary[i].check == true + // to check if the book is read or not. + if (myLibrary[i].check == true) { readStatus = "Yes"; } else { readStatus = "No"; @@ -89,12 +95,15 @@ function render() { }); //add delete button to every row and render again + // Fix : + // change delBut to delButton because we declare it. + // The event listener is "clicks" instead of "click". 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();