Skip to content

Commit 02a6b5f

Browse files
committed
check all variable fix validtion clean the code
1 parent b6adcd2 commit 02a6b5f

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

debugging/book-library/script.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ window.addEventListener("load", function (e) {
1616
//just one thing need to check
1717
function populateStorage() {
1818
if (myLibrary.length === 0) {
19-
let book1 = new Book("Robison Crusoe", "Daniel Defoe", 252, true);
20-
let book2 = new Book(
19+
const book1 = new Book("Robison Crusoe", "Daniel Defoe", 252, true);
20+
const book2 = new Book(
2121
"The Old Man and the Sea",
2222
"Ernest Hemingway",
2323
127,
@@ -35,11 +35,11 @@ function submit() {
3535
const titleValue = titleInput.value.trim();
3636
const authorValue = authorInput.value.trim();
3737
const pagesValue = Number(pagesInput.value);
38-
if (!titleValue || !authorValue || Number.isFinite(!pagesValue) || pagesValue <= 0) {
38+
if (!titleValue || !authorValue || !Number.isFinite(pagesValue) || pagesValue <= 0) {
3939
alert("Please fill all fields!");
4040
return;
4141
} else {
42-
let book = new Book(
42+
const book = new Book(
4343
titleValue,
4444
authorValue,
4545
pagesValue,
@@ -58,11 +58,10 @@ function Book(title, author, pages, check) {
5858
}
5959

6060
function render() {
61-
let table = document.getElementById("display");
6261
const tableBody = document.getElementById("tbody");
6362
tableBody.textContent = "";
6463
//insert updated row and cells
65-
let length = myLibrary.length;
64+
const length = myLibrary.length;
6665
for (let i = 0; i < length; i++) {
6766
const row = tableBody.insertRow(); // why (1) not i+1 insert <tr> with four <td>
6867
const titleCell = row.insertCell(0); // the table.rows and row.cells are HTMLCollection,not a real array, but they behave like array(indexed,length) . they are DOM collections
@@ -75,15 +74,10 @@ function render() {
7574
pagesCell.textContent = myLibrary[i].pages;
7675

7776
//add and wait for action for read/unread button
78-
let changeReadBut = document.createElement("button");
77+
const changeReadBut = document.createElement("button");
7978
changeReadBut.className = "btn btn-success";
8079
wasReadCell.appendChild(changeReadBut);
8180
let readStatus = "";
82-
if (myLibrary[i].check === true) {
83-
readStatus = "Yes";
84-
} else {
85-
readStatus = "No";
86-
}
8781
readStatus= myLibrary[i].check===true? "yes":"no";
8882

8983
changeReadBut.textContent = readStatus;

0 commit comments

Comments
 (0)