London | 26-ITP-May | Chun Yan Wong | Sprint 2 | Book library - #525
London | 26-ITP-May | Chun Yan Wong | Sprint 2 | Book library#525cywong-dev wants to merge 26 commits into
Conversation
for the function submit
for typo mistake
Fix variable name for delete button in script.js
There is no event called clicks
for wrong insertion order
Read/unread saves the wrong answer
Fix the sequence
Remove newline characters; Change "127" to 127 ; Simplify two push statement to one push statement
Refactor submit function to improve input validation.
Refactor row deletion logic to use while loop for clarity.
Refactor loop to directly use myLibrary.length and simplify read status button logic.
Removed the call to render() when initializing the library.
cjyuan
left a comment
There was a problem hiding this comment.
-
The checkboxes in the PR description are not yet properly marked up in Markdown syntax.
-
Can you 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.mdDoing so can help me speed up the review process. Thanks.
Fix multiple issues in book library functionality, including correcting variable names, logic for read status, and ensuring proper rendering of books.
|
Yes, changed. Please kindly check? |
cjyuan
left a comment
There was a problem hiding this comment.
According to https://validator.w3.org/, there are errors in your index.html. Can you fix these errors?
Updated title and meta tags in the head section. Changed input types for title and author fields to 'text'.
Fixed. Please kindly check? |
Remove my name in the comment as I am the only one developer in the project
Clear the table's inner HTML to remove old rows.
Remove unused variable 'rowsNumber' in render function.
Updated the submit function to use the correct trimmed value
Added a helper function to display status messages in the UI and updated the submit function to use it. Also fixed variable name from 'mylibrary' to 'myLibrary'.
Added table header for book library display.
| let length = myLibrary.length; | ||
| for (let i = 0; i < length; i++) { | ||
| let row = table.insertRow(1); | ||
| table.innerHTML = ""; |
There was a problem hiding this comment.
You could also clear only <tbody>. This way, you don't need to recreate the header row.
| <input | ||
| type="submit" | ||
| value="Submit" | ||
| class="btn btn-primary" | ||
| onclick="submit();" | ||
| /> |
There was a problem hiding this comment.
Could you use AI to find out the tradeoff between attaching event listener in HTML and in JavaScript?
| min="1" | ||
| step="1" | ||
| oninput="this.value = this.value.replace(/[^0-9]/g, '').replace(/^0+/, '');" | ||
| required |
There was a problem hiding this comment.
-
The JS code works to certain extent but it introduces some unusual behavior to the input field. For example, when I pressed '1', '2', '3', 'e', the input field was cleared.
-
Adding
min="1",step="1"andrequiredwould be enough if the input element is inside a<form>. When the input elements are in a<form>, the constraints would have been checked by the browser when the user submits the form (clicks the "Submit" button).
| return; | ||
| } | ||
|
|
||
| let book = new Book(titleValue, authorValue, pagesValue, check.checked); |
There was a problem hiding this comment.
This would lead to
- New books store page count as strings.
- The books created in
populateStorage()store page count as numbers.
Could you find a way to represent same kind of value using the same data type?
Also, even if the HTML code is already prepared to accept only input containing digits, it is still a safe practice to check the input again in JS.
Learners, PR Template
Self checklist
Changelist
This PR provides the answer for the coursework book library