Skip to content

Commit 653b481

Browse files
committed
fixed naming inconsistency and other bugs
1 parent d99a1ab commit 653b481

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

‎debugging/book-library/script.js‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@ const readCheckbox = document.getElementById("check");
2727
//check the right input from forms and if its ok -> add the new book (object in array)
2828
//via Book function and start render function
2929
function submit() {
30+
const trimmedTitle = titleInput.value.trim();
31+
const trimmedAuthor = authorInput.value.trim();
32+
const trimmedPages = +pagesInput.value.trim();
33+
3034
if (
31-
!titleInput.value.trim() ||
32-
!authorInput.value.trim() ||
33-
!pagesInput.value.trim()
35+
!trimmedTitle ||
36+
!trimmedAuthor ||
37+
!trimmedPages
3438
) {
3539
alert("Please fill all fields!");
3640
return false;
3741
} else {
38-
let book = new Book(titleInput.value, authorInput.value, pagesInput.value, readCheckbox.checked);
42+
let book = new Book(trimmedTitle, trimmedAuthor, trimmedPages, readCheckbox.checked);
3943
myLibrary.push(book);
44+
4045
titleInput.value = "";
4146
authorInput.value = "";
4247
pagesInput.value = "";
@@ -46,10 +51,10 @@ function submit() {
4651
}
4752

4853
function Book(title, author, pages, check) {
49-
this.titleInput = title;
50-
this.authorInput = author;
51-
this.pagesInput = pages;
52-
this.readCheckbox = check;
54+
this.title = title;
55+
this.author = author;
56+
this.pages = pages;
57+
this.check = check;
5358
}
5459

5560
function render() {
@@ -68,9 +73,9 @@ function render() {
6873
const pagesCell = row.insertCell(2);
6974
const wasReadCell = row.insertCell(3);
7075
const deleteCell = row.insertCell(4);
71-
titleCell.textContent = myLibrary[i].titleInput;
72-
authorCell.textContent = myLibrary[i].authorInput;
73-
pagesCell.textContent = myLibrary[i].pagesInput;
76+
titleCell.textContent = myLibrary[i].title;
77+
authorCell.textContent = myLibrary[i].author;
78+
pagesCell.textContent = myLibrary[i].pages;
7479

7580
//add and wait for action for read/unread button
7681
const changeBut = document.createElement("button");

0 commit comments

Comments
 (0)