Birmingham | 26-ITP-May | Tobias Amaechina | Sprint 2 | Book-library - #516
Birmingham | 26-ITP-May | Tobias Amaechina | Sprint 2 | Book-library#516Tobias-Amaechina wants to merge 26 commits into
Conversation
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.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
abaaa14 to
2606f98
Compare
cjyuan
left a comment
There was a problem hiding this comment.
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.md
Doing so can help me speed up the review process. Thanks.
|
Thank you CY for the link , it definitely helped and the HTML has been validated , Thanks |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
7eaaef1 to
bbef966
Compare
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
Changes look good.
I only have a few more possible improvements for you to consider.
| value="Submit" | ||
| class="btn btn-primary" | ||
| onclick="submit();" | ||
| onclick="handleSubmit();" |
There was a problem hiding this comment.
Suggestion: Look up the trade-off among different approaches for attaching event listener to HTML elements. In particulars,
- Via HTML attribute in HTML
- In JS, using
.addEventListener()
| let book = new Book(title.value, title.value, pages.value, check.checked); | ||
| library.push(book); | ||
| render(); | ||
| if (!title || !author || !pages || pages <= 0) { |
There was a problem hiding this comment.
What type of number should pages be? Could it be NaN?
There was a problem hiding this comment.
Although the HTML is prepared to reject non positive whole number, it is a safer practice to also fully check the input in JS code to ensure it is a positive whole number.
| @@ -62,13 +65,13 @@ <h1>Library</h1> | |||
| />Read | |||
| </label> | |||
There was a problem hiding this comment.
Did you notice the checkbox is not showing in the form?
The issue is related to Bootstrap 4.4.1 and AI can point out a solution if you show the code to it (and mention the code uses Bootstrap 4.4.1)
Fixing this is optional.
| } | ||
|
|
||
| // attach listener | ||
| document.getElementById("submit-btn").addEventListener("click", handleSubmit); |
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.
| const check = document.getElementById("check"); | ||
| // Handle form submission | ||
| function handleSubmit(e) { | ||
| e.preventDefault();//stop the form from reloading the page |
There was a problem hiding this comment.
Note: This method does not stop the page from reloading directly. It stops something else that makes the browser from loading a new page. It's an important method to understand.
| let book = new Book(title.value, title.value, pages.value, check.checked); | ||
| library.push(book); | ||
| render(); | ||
| if (!title || !author || !pages || pages <= 0) { |
There was a problem hiding this comment.
Although the HTML is prepared to reject non positive whole number, it is a safer practice to also fully check the input in JS code to ensure it is a positive whole number.
Self checklist
Changelist
Corrected validation logic to ensure title, author, and pages fields are required before adding a book.
Fixed bug where the author field was ignored and replaced with the title value.
Corrected array reference (library → myLibrary) to prevent runtime errors when adding books.
Repaired table‑rendering loop by fixing a missing parenthesis in the row‑deletion logic.
Corrected read/unread status logic so check === true displays “Yes”.
Fixed delete‑button creation:
Corrected variable name (delButton instead of delBut)
Removed accidental reassignment of the button element
Corrected event listener from "clicks" to "click"
Ensured delete action removes the correct book and re-renders the table