West Midlands | 26-Jan-ITP | Fida Ali Zada | Sprint 2 | Book-Library - #439
West Midlands | 26-Jan-ITP | Fida Ali Zada | Sprint 2 | Book-Library#439alizada-dev wants to merge 8 commits into
Conversation
| !titleInput.value.trim() || | ||
| !authorInput.value.trim() || | ||
| !pagesInput.value.trim() | ||
| ) { | ||
| 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(titleInput.value, authorInput.value, pagesInput.value, readCheckbox.checked); |
There was a problem hiding this comment.
-
You checked the trimmed value but you are using the untrimmed values. A better approach is to first store the preprocessed input in variables, then use those cleaned values consistently throughout the rest of the code.
-
pagesInput.valueis a string, and a number in scientific format may look unnatural as "number of pages".
There was a problem hiding this comment.
Got it, sir. Thank you for this out. Could you check if it is okay this time?
function submit() {
const trimmedTitle = titleInput.value.trim();
const trimmedAuthor = authorInput.value.trim();
const trimmedPages = +pagesInput.value.trim();
if (
!trimmedTitle ||
!trimmedAuthor ||
!trimmedPages
) {
alert("Please fill all fields!");
return false;
} else {
let book = new Book(trimmedTitle, trimmedAuthor, trimmedPages, readCheckbox.checked);
myLibrary.push(book);
titleInput.value = "";
authorInput.value = "";
pagesInput.value = "";
readCheckbox.checked = false;
render();
}
}
| this.titleInput = title; | ||
| this.authorInput = author; | ||
| this.pagesInput = pages; | ||
| this.readCheckbox = check; |
There was a problem hiding this comment.
These are the properties of a book. They are not DOM elements. The original names (except maybe check) are more natural.
There was a problem hiding this comment.
You are absolutely right.
function Book(title, author, pages, check) {
this.title = title;
this.author = author;
this.pages = pages;
this.check = check;
}
titleCell.textContent = myLibrary[i].title;
authorCell.textContent = myLibrary[i].author;
pagesCell.textContent = myLibrary[i].pages;
|
Changes look good. |
|
Closing PR because the January ITP run has finished. Feel free to re-open if you're still working on it. |
Learners, PR Template
Self checklist
Changelist
Bugs that I fixed:
Please let me know of any more bugs (if yet to be fixed)