diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71e..8bcc4dc61 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,15 +1,15 @@ - + - + My Book Library + + - - - + + + +

Library

Add books to your virtual library

- @@ -31,7 +32,7 @@

Library

Library /> Library - - +
+ - + \ No newline at end of file diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d3..6618deb56 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -29,6 +29,8 @@ const check = document.getElementById("check"); //via Book function and start render function function submit() { if ( + author.value == null || + author.value == "" || title.value == null || title.value == "" || pages.value == null || @@ -37,8 +39,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(); } } @@ -54,13 +56,14 @@ 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--) { + // there was a syntax error here the ")" was missing table.deleteRow(n); } //insert updated row and cells let length = myLibrary.length; for (let i = 0; i < length; i++) { - let row = table.insertRow(1); + let row = table.insertRow(-1); let titleCell = row.insertCell(0); let authorCell = row.insertCell(1); let pagesCell = row.insertCell(2); @@ -76,7 +79,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"; @@ -89,15 +92,20 @@ function render() { }); //add delete button to every row and render again - let delButton = document.createElement("button"); + let delBut = document.createElement("button"); delBut.id = i + 5; deleteCell.appendChild(delBut); delBut.className = "btn btn-warning"; delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { - alert(`You've deleted title: ${myLibrary[i].title}`); + delBut.addEventListener("click", function () { + const deletedTitle = myLibrary[i].title; + myLibrary.splice(i, 1); render(); + + setTimeout(function () { + alert(`You've deleted title: ${deletedTitle}`); + }, 0.5); }); } }