diff --git a/debugging/book-library/.vscode/settings.json b/debugging/book-library/.vscode/settings.json
new file mode 100644
index 00000000..da2a0bdb
--- /dev/null
+++ b/debugging/book-library/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "cSpell.words": ["Robison"]
+}
diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html
index 23acfa71..b9f1e43b 100644
--- a/debugging/book-library/index.html
+++ b/debugging/book-library/index.html
@@ -1,12 +1,9 @@
-
-
+
+
-
-
+ My Book Library
+
+
@@ -31,7 +28,7 @@ Library
Library
/>
Library
type="submit"
value="Submit"
class="btn btn-primary"
- onclick="submit();"
+ onclick="submit()"
/>
diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js
index 75ce6c1d..b4201fe2 100644
--- a/debugging/book-library/script.js
+++ b/debugging/book-library/script.js
@@ -31,16 +31,24 @@ function submit() {
if (
title.value == null ||
title.value == "" ||
+ author.value == null ||
+ author.value == "" ||
pages.value == null ||
pages.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();
}
+
+ // clear the form after submit
+ title.value = "";
+ author.value = "";
+ pages.value = "";
+ check.checked = false;
}
function Book(title, author, pages, check) {
@@ -54,7 +62,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
@@ -76,7 +84,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 +98,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();