Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion debugging/book-library/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h1>Library</h1>
type="submit"
value="Submit"
class="btn btn-primary"
onclick="submit();"
id ="submit-btn"
/>
</div>
</div>
Expand Down
25 changes: 15 additions & 10 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
let myLibrary = [];

window.addEventListener("load", function (e) {
populateStorage();
render();
Expand All @@ -16,14 +15,19 @@ function populateStorage() {
);
myLibrary.push(book1);
myLibrary.push(book2);
render();
}
}

const title = document.getElementById("title");
const author = document.getElementById("author");
const pages = document.getElementById("pages");
const check = document.getElementById("check");
const submitBtn = document.getElementById("submit-btn");

submitBtn.addEventListener("click", function (event) {
event.preventDefault();
submit();
});

//check the right input from forms and if its ok -> add the new book (object in array)
//via Book function and start render function
Expand All @@ -37,8 +41,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();
}
}
Expand All @@ -54,9 +58,9 @@ 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
let length = myLibrary.length;
for (let i = 0; i < length; i++) {
Expand All @@ -77,9 +81,9 @@ function render() {
wasReadCell.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
readStatus = "Yes";
} else {
readStatus = "No";
} else {
readStatus = "Yes";
}
changeBut.innerText = readStatus;

Expand All @@ -89,15 +93,16 @@ 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();
});
}
}

Loading