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
4 changes: 2 additions & 2 deletions debugging/book-library/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title> </title>
<title> Book-Library </title>
<meta
charset="utf-8"
name="viewport"
Expand Down Expand Up @@ -47,7 +47,7 @@ <h1>Library</h1>
/>
<label for="pages">Pages:</label>
<input
type="number"
type="number" min="1" step="1"
class="form-control"
id="pages"
name="pages"
Expand Down
19 changes: 11 additions & 8 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ function submit() {
if (
title.value == null ||
title.value == "" ||
pages.value == null ||
author.value === "" ||
parseInt(pages.value) <=0 ||
isNaN(pages.value) ||
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();
}

Choose a reason for hiding this comment

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

image
I'm still able to add a book even if one field is empty

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 fixed the issue, thank you for the review.

}
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 @@ -77,9 +79,10 @@ function render() {
wasReadCell.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
readStatus = "Yes";
readStatus = "NO";

Choose a reason for hiding this comment

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

If you don't read a book, color of button shouldn't be green, maybe we should change to something else in order to increase user experience.

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 added a RED background colour when readStatus = "NO";

changeBut.style.backgroundColor = "red"
} else {
readStatus = "No";
readStatus = "Yes";
}
changeBut.innerText = readStatus;

Expand All @@ -89,12 +92,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