-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
West Midlands | Samira Hekmati | Module-Data-Flows | Sprint-2 | Book-library #142
base: main
Are you sure you want to change the base?
West Midlands | Samira Hekmati | Module-Data-Flows | Sprint-2 | Book-library #142
Conversation
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.
In terms of input validation,
- Are all input properly checked?
- Can
.value
benull
? (Do we need to checksomeInputElement.value == null
?) - What if a user enters only space characters in the "title" input field?
- What if a users enters
-1
or3.1416
in the "pages" input field?
There are also some errors in the index.html
.
debugging/book-library/script.js
Outdated
delBut.className = "btn btn-warning"; | ||
delBut.innerHTML = "Delete"; | ||
delBut.addEventListener("clicks", function () { | ||
delButton.id = i + 5; |
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.
- Do you think the value assigned to this
id
attribute is unique? - Do you think there is a need to assign any id attribute to
delButton
? - Do you think there is a need to assign any id attribute to
changeBut
(at line 79)? - Can you think of a more consistent way to name the variables representing the two buttons?
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.
you're right @cjyuan The value i + 5 for the id attribute isn't guaranteed to be unique.
Instead of using i + 5 (which is not reliable),I can simply use the i value as the id for the delete button since it's guaranteed to be unique within the context of the current render.
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.
infact no need to assign an ID here. I am already using the i index inside the click event listener to know which book was clicked (since i uniquely identifies each book in the loop).
I can simply remove the assignment of the id for the delete button.
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.
Similarly to the delButton, there is no need to assign an id attribute to the changeBut button (line 79).
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.
changeBut → toggleReadButton: The button's purpose is to toggle the "read" status of the book, so a more descriptive name would help clarify its role.
delButton → deleteButton: This name is already clear but can be made consistent with the other button name by making it follow the same pattern.
debugging/book-library/script.js
Outdated
@@ -54,7 +58,7 @@ function render() { | |||
let table = document.getElementById("display"); | |||
let rowsNumber = table.rows.length; | |||
//delete old table | |||
for (let n = rowsNumber - 1; n > 0; n-- { | |||
for (let n = rowsNumber - 1; n > 0; n--) { |
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.
Can you think of a more efficient way to remove all rows (except the <th>...</th>
) in the table?
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! simply clear all the rows except the header row by removing all child elements from the (or equivalent body section of the table). This avoids looping through the rows and directly empties the content of the table
Can .value be null? (Do we need to check someInputElement.value == null?) |
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.