-
-
Notifications
You must be signed in to change notification settings - Fork 127
NW | 25-ITP-Sep | TzeMing Ho | Sprint 2 | book-library-debugging #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Can you check if any of this general feedback can help you further improve your code? Doing so can help me speed up the review process. Thanks. |
Thank you CJ, The feedback document is very benefitical. I didn't notice that the project I sumbited still got so many bugs. Thank you for letting me know. I have made some improvements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your book library works, I just used it and it seems okay, @cjyuan do you have any other comments so that I can mark it complete, thanks
cjyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code works. I just have a few suggestions.
debugging/book-library/index.html
Outdated
|
|
||
| <div id="demo" class="collapse"> | ||
| <div class="form-group"> | ||
| <form class="form-group" id="book-form" onsubmit="handleSubmit(event)" > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could consider attaching event handler to the form in JS (to keep HTML code free of JS code)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I have removed the function from the HTML and created an eventListener in the script.
debugging/book-library/script.js
Outdated
| pages.value == "" | ||
| !titleInput.value.trim() || | ||
| !authorInput.value.trim() || | ||
| pagesInput.value <= 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some "weird" numbers (that shouldn't be considered valid page count) could still pass this check. Can you figure out what these numbers are and "handle" them appropriately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried my best to think of the weird numbers could be some spaces before or after the actual numbers. I added a trim process for the pages value as well. I hope this will help prevent some strange situations.
debugging/book-library/script.js
Outdated
| } else { | ||
| let book = new Book(title.value, title.value, pages.value, check.checked); | ||
| library.push(book); | ||
| let book = new Book(String(titleInput.value), String(authorInput.value), Number(pagesInput.value), checkInput.checked); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.value is always a string. And on line 39, they could still contain leading or trailing spaces.
debugging/book-library/script.js
Outdated
| for (let n = rowsNumber - 1; n > 0; n-- { | ||
| table.deleteRow(n); | ||
| } | ||
| let tableBody = document.getElementById("display-body") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could consider (in code refactoring stage) change let to const for all variables that are not going to be reassigned a value.
cjyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look great!
| let pagesValue = Number(pagesInput.value.trim()); | ||
| let read = checkInput.checked; | ||
| if ( | ||
| !titleInput.value.trim() || | ||
| !authorInput.value.trim() || | ||
| pagesInput.value <= 0 | ||
| !titleValue|| | ||
| !authorValue || | ||
| !Number.isInteger(pagesValue) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trim of pagesinput.value is optional but ensuring pagesValue is an integer would prevent "weird" page count. So, well done!
| const bookForm = document.getElementById("book-form") | ||
| bookForm.addEventListener("submit", (event) => handleSubmit(event)); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to group code that is to be executed once (line 52) in one place (to make locating them easier). For example, in the window.onload callback function (lines 3-5).
| </table> | ||
|
|
||
| <script src="script.js"></script> | ||
| <script src="script.js" defer></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Consider loading script.js as an ES module to isolate its scope from the global context:
<script src="script.js" type="module"></script>
This ensures that variables, functions, and imports in script.js don’t leak into the global namespace, helps prevent naming conflicts, and enables the use of modern JavaScript features like import and export.
- Also, with
type="module",deferis automatically enforced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. It is something useful. Good to know.
Learners, PR Template
Self checklist
Changelist
I have debugged the book library, which now populates the book collection, displays book information correctly, adds books, and deletes books.