Skip to content
Open
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
8 changes: 4 additions & 4 deletions debugging/book-library/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<title> </title>
<title>Book Library</title>
<meta
charset="utf-8"
name="viewport"
Expand Down Expand Up @@ -65,7 +65,7 @@ <h1>Library</h1>
type="submit"
value="Submit"
class="btn btn-primary"
onclick="submit();"
id="submit"
/>
</div>
</div>
Expand All @@ -91,6 +91,6 @@ <h1>Library</h1>
</tbody>
</table>

<script src="script.js"></script>
<script src="script.js" defer></script>
</body>
</html>
30 changes: 19 additions & 11 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let myLibrary = [];

window.addEventListener("load", function (e) {
populateStorage();
render();
//render();
});

function populateStorage() {
Expand Down Expand Up @@ -32,17 +32,22 @@ function submit() {
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);
let book = new Book(title.value, author.value, pages.value, check.checked);
myLibrary.push(book);
render();
}
}

const submitInput = document.getElementById("submit");
submitInput.addEventListener("click", submit);

function Book(title, author, pages, check) {
this.title = title;
this.author = author;
Expand All @@ -54,7 +59,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 >= 1; n--) {
table.deleteRow(n);
}
//insert updated row and cells
Expand All @@ -76,11 +81,12 @@ 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";
}

changeBut.innerText = readStatus;

changeBut.addEventListener("click", function () {
Expand All @@ -89,12 +95,14 @@ 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;

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();
Expand Down
Loading