Skip to content
4 changes: 2 additions & 2 deletions debugging/book-library/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ <h1>Library</h1>
/>Read
</label>
<input
type="submit"
type="button"
value="Submit"
class="btn btn-primary"
onclick="submit();"
onclick="addButton();"
/>
</div>
</div>
Expand Down
16 changes: 9 additions & 7 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ 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() {
function addBook() {
if (
title.value == null ||
title.value == "" ||
pages.value == null ||
pages.value == ""
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);
myLibrary.push(book);
render();
}
}
Expand All @@ -54,7 +56,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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could consider using a more efficient approach to clear the table.

//insert updated row and cells
Expand All @@ -76,7 +78,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";
Expand All @@ -89,12 +91,12 @@ 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 () {
delBut.addEventListener("click", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
Expand Down
Loading