Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

samirahekmati
Copy link

@samirahekmati samirahekmati commented Jan 13, 2025

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@samirahekmati samirahekmati added the Needs Review Participant to add when requesting review label Jan 13, 2025
Copy link

@cjyuan cjyuan left a 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,

  1. Are all input properly checked?
  2. Can .value be null? (Do we need to check someInputElement.value == null?)
  3. What if a user enters only space characters in the "title" input field?
  4. What if a users enters -1 or 3.1416 in the "pages" input field?

There are also some errors in the index.html.

delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
delButton.id = i + 5;
Copy link

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?

Copy link
Author

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.

Copy link
Author

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.

Copy link
Author

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).

Copy link
Author

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.

@@ -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--) {
Copy link

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?

Copy link
Author

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

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Jan 16, 2025
@samirahekmati
Copy link
Author

Can .value be null? (Do we need to check someInputElement.value == null?)
Answer: No, .value will not be null on a valid input element. The .value of an input field is an empty string ("") if the user has not entered anything, not null. So, checking for value == null is unnecessary.

@samirahekmati samirahekmati added Complete Participant to add when work is complete and review comments have been addressed and removed Reviewed Volunteer to add when completing a review labels Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Participant to add when work is complete and review comments have been addressed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants