Skip to content

London | 26-ITP-May | Chun Yan Wong | Sprint 2 | Book library - #525

Open
cywong-dev wants to merge 26 commits into
CodeYourFuture:mainfrom
cywong-dev:book-library
Open

London | 26-ITP-May | Chun Yan Wong | Sprint 2 | Book library#525
cywong-dev wants to merge 26 commits into
CodeYourFuture:mainfrom
cywong-dev:book-library

Conversation

@cywong-dev

@cywong-dev cywong-dev commented Aug 7, 2026

Copy link
Copy Markdown

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

This PR provides the answer for the coursework book library

Fix variable name for delete button in script.js
There is no event called clicks
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.
@cywong-dev cywong-dev added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Data-Flows The name of the module. labels Aug 7, 2026

@cjyuan cjyuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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 Aug 7, 2026
Fix multiple issues in book library functionality, including correcting variable names, logic for read status, and ensuring proper rendering of books.
@cywong-dev cywong-dev 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 Aug 9, 2026
@cywong-dev

Copy link
Copy Markdown
Author

Yes, changed. Please kindly check?

@cjyuan cjyuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

According to https://validator.w3.org/, there are errors in your index.html. Can you fix these errors?

Comment thread debugging/book-library/script.js
Comment thread debugging/book-library/script.js Outdated
Comment thread debugging/book-library/script.js Outdated
Comment thread debugging/book-library/script.js Outdated
Comment thread debugging/book-library/script.js Outdated
@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 Aug 10, 2026
Updated title and meta tags in the head section. Changed input types for title and author fields to 'text'.
@cywong-dev

Copy link
Copy Markdown
Author

According to https://validator.w3.org/, there are errors in your index.html. Can you fix these errors?

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.
@cywong-dev cywong-dev 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 Aug 10, 2026
Comment thread debugging/book-library/script.js Outdated
let length = myLibrary.length;
for (let i = 0; i < length; i++) {
let row = table.insertRow(1);
table.innerHTML = "";

@cjyuan cjyuan Aug 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could also clear only <tbody>. This way, you don't need to recreate the header row.

Comment thread debugging/book-library/script.js Outdated
Comment thread debugging/book-library/script.js Outdated
Comment thread debugging/book-library/index.html
Comment on lines 62 to 67
<input
type="submit"
value="Submit"
class="btn btn-primary"
onclick="submit();"
/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you use AI to find out the tradeoff between attaching event listener in HTML and in JavaScript?

@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 Aug 10, 2026
Comment on lines +52 to 55
min="1"
step="1"
oninput="this.value = this.value.replace(/[^0-9]/g, '').replace(/^0+/, '');"
required

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • 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" and required would 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).

Comment thread debugging/book-library/script.js Outdated
return;
}

let book = new Book(titleValue, authorValue, pagesValue, check.checked);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Data-Flows The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants