Skip to content

Commit 0fc4d1e

Browse files
update the new version of js.
1 parent a55ce60 commit 0fc4d1e

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

debugging/book-library/script.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ function addBook() {
2929
const authorValue = authorInput.value.trim();
3030
const pagesValue = Number(pagesInput.value);
3131

32-
if (!titleValue || !authorValue || Number.isNaN (pagesValue)<= 0) {
32+
if (
33+
!titleValue ||
34+
!authorValue ||
35+
Number.isNaN(pagesValue) ||
36+
pagesValue <= 0
37+
) {
3338
alert("Please fill all fields correctly!");
3439
return;
3540
}
@@ -40,8 +45,8 @@ function addBook() {
4045
pagesValue,
4146
checkInput.checked
4247
);
43-
myLibrary.push(book);
4448

49+
myLibrary.push(book);
4550
render();
4651
}
4752

@@ -53,20 +58,12 @@ function Book(title, author, pages, check) {
5358
}
5459

5560
function render() {
56-
const table = document.getElementById("display");
57-
58-
table.innerHTML = `
59-
<tr>
60-
<th>Title</th>
61-
<th>Author</th>
62-
<th>Pages</th>
63-
<th>Read</th>
64-
<th>Delete</th>
65-
</tr>
66-
`;
61+
const tbody = document.querySelector("#display tbody");
62+
63+
tbody.innerHTML = "";
6764

6865
myLibrary.forEach((book, i) => {
69-
const row = table.insertRow();
66+
const row = tbody.insertRow();
7067

7168
const titleCell = row.insertCell(0);
7269
const authorCell = row.insertCell(1);
@@ -102,4 +99,5 @@ function render() {
10299
deleteCell.appendChild(deleteBtn);
103100
});
104101
}
102+
105103
window.addBook = addBook;

0 commit comments

Comments
 (0)