Glasgow | 26-ITP-May | Francesco Romano Monda | Sprint 2 | Book Library - #553
Glasgow | 26-ITP-May | Francesco Romano Monda | Sprint 2 | Book Library#553fromonda wants to merge 3 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
Could you also check if any of this general feedback can help you further improve your code?
https://github.com/CodeYourFuture/Module-Data-Flows/blob/general-review-feedback/debugging/book-library/feedback.md
Doing so can help me speed up the review process. Thanks.
Thank you for pointing me towards the improvement guidelines and for trying to speed up the review process. I put all the improvements indicated into practice, although it took some time. I hope the refactoring, input validation, and other changes are better now. |
cjyuan
left a comment
There was a problem hiding this comment.
Code looks pretty solid.
There seems to be a bug.
| @@ -52,24 +51,19 @@ <h1>Library</h1> | |||
| id="pages" | |||
| name="pages" | |||
| required | |||
| min="1" | |||
| step="1" | |||
| /> | |||
There was a problem hiding this comment.
Even with these constraints, currently the browser would still allow a user to submit value like 12.345 or -100. Could you find out why and then fix the issue?
There was a problem hiding this comment.
I tested this again and found that decimal and negative page values are now rejected and the error message is displayed. It is possible that this issue occurred before I added the error message.
There was a problem hiding this comment.
The error message you mentioned is generated by your JS code, and not by the browser.
The browser will only check the input against those constraints when a user submits a form. Currently those input elements are not inside a form, and that's why the browser does not enforce the constraints.
| submitBtn.addEventListener("click", submitBook); | ||
|
|
||
| // Add initial books | ||
| const book1 = new Book("Robinson Crusoe", "Daniel Defoe", 252, true); | ||
| const book2 = new Book( | ||
| "The Old Man and the Sea", | ||
| "Ernest Hemingway", | ||
| 127, | ||
| true | ||
| ); | ||
|
|
||
| myLibrary.push(book1); | ||
| myLibrary.push(book2); | ||
| render(); |
There was a problem hiding this comment.
Could consider placing all code that runs once on page load in a single function. For example, you could put it inside the page load callback or create a function named init() or setup() and call it once when the page loads.
This makes it easier to locate and manage all the code that runs once when the app starts.
There was a problem hiding this comment.
I have updated my code by creating an init() function and moving the code that runs when the application starts into it.
| library.push(book); | ||
| render(); | ||
| if (!title || !author || !Number.isInteger(pages) || pages < 1) { | ||
| showMessage("Please enter valid book information.", "danger"); |
There was a problem hiding this comment.
When I clicked the Submit button without any input, I couldn't see any error message.
There was a problem hiding this comment.
I found the issue: I had not included an element with id="message" in my HTML. I added the missing element, and the validation error message now displays correctly when the Submit button is clicked without any input.
There was a problem hiding this comment.
This was the bug I wanted you to find. You fixed it!
This issue may have been related to the changes I made while fixing the validation and error-message handling. |
| const titleInput = document.getElementById("title"); | ||
| const authorInput = document.getElementById("author"); | ||
| const pagesInput = document.getElementById("pages"); | ||
| const checkInput = document.getElementById("check"); | ||
| const submitBtn = document.getElementById("submitBtn"); | ||
| const bookList = document.getElementById("bookList"); | ||
| const messageEl = document.getElementById("message"); |
There was a problem hiding this comment.
This approach is actually safer and preferred. Declaring these shared variables using let is too risky.
|
I will mark this PR as "Complete" first. |
Self checklist
Changelist