Skip to content

Conversation

@M-Abdoon
Copy link

@M-Abdoon M-Abdoon commented Dec 6, 2025

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

finished book library exercise.

Questions

No questions so far. Thank you.

@M-Abdoon M-Abdoon added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 6, 2025
Copy link
Contributor

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

There are some debugging code left in script.js. Can you remove it to keep the code clean?

Comment on lines 29 to 32
let titleInput = document.getElementById("title").value;
let authorInput = document.getElementById("author").value.trim();
const pagesInput = Number(document.getElementById("pages").value.trim());
const checkBtn = document.getElementById("check");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Title may also contain leading/trailing space.
  • The first three variables are assigned the input values (and not DOM elements). Why not do the same to the 4th variable?
  • Note: Number() ignores leading/trailing space in a string, so trim() is optional on line 31.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first three variables store the current input values because we need them directly, while the checkBtn is only needed to attach a click event to it, not it's value. so that's why I handled it differently.

Comment on lines +34 to +35
titleInput = titleInput.replace(/</g, "");
authorInput = authorInput.replace(/</g, "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if a book title really contains a "<" character?
Why only remove '<' and not all "special characters" that may be misinterpreted as part of HTML code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought only '<' could be misinterpreted as part of HTML.
I removed the validation completely and used .textContent instead of .innerHTML when assigning the input to the new object, so the page is not affected when displaying the text.

authorInput = authorInput.replace(/</g, "");

console.log(titleInput);
if ( titleInput == "" || authorInput == "" || pagesInput == "" ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why compare pagesInput to ""?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure whether the input isn't empty or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pagesInput is a number.

Comment on lines 75 to 76
titleCell.innerHTML = myLibrary[i].title;
authorCell.innerHTML = myLibrary[i].author;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By assigning a value to .innerHTML, some "special characters" in the book title may be misinterpreted as part of HTML code.

Copy link
Author

@M-Abdoon M-Abdoon Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I used .textContent instead so we ignore any special characters.

Comment on lines 78 to 89
let readStatus = "";
if (myLibrary[i].check == false) {
if (myLibrary[i].check == true) {
readStatus = "Yes";
} else {
readStatus = "No";
}
changeBut.innerText = readStatus;
changeButton.innerText = readStatus;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to simplify the code on lines 83-89 into one or two lines of code. As a challenge, can you simplify it?

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Dec 7, 2025
@M-Abdoon
Copy link
Author

M-Abdoon commented Dec 7, 2025

There are some debugging code left in script.js. Can you remove it to keep the code clean?

I just modified the code and made the required changes. Thank you.

@M-Abdoon M-Abdoon added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Dec 7, 2025
@cjyuan
Copy link
Contributor

cjyuan commented Dec 7, 2025

Changes look good.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants