Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ function submit() {
title.value == "" ||
pages.value == null ||
pages.value == ""
|| author.value == null ||
author.value == ""
) {
alert("Please fill all fields!");

Choose a reason for hiding this comment

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

Is there any input validation missing from the pages? What about the author?

Copy link
Author

Choose a reason for hiding this comment

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

I have done all the input validation.

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();
}
}
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);
}
//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) {
readStatus = "Yes";
} else {
readStatus = "No";
Expand All @@ -90,14 +92,16 @@ 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 () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
delButton.id = i + 5;
deleteCell.appendChild(delButton);
delButton.className = "btn btn-warning";
delButton.innerHTML = "Delete";
delButton.addEventListener("click", function () {
const index = parseInt(this.id) - 5; // get index from button id
if (confirm(`Are you sure you want to delete "${myLibrary[index].title}"?`)) {
myLibrary.splice(index, 1);
render();
}
});
}
}