Skip to content

London | 26-ITP-May | Khaliun Baatarkhuu | Sprint 2 | Book Library - #535

Open
khaliun-dev wants to merge 6 commits into
CodeYourFuture:mainfrom
khaliun-dev:sprint-2/book-library
Open

London | 26-ITP-May | Khaliun Baatarkhuu | Sprint 2 | Book Library#535
khaliun-dev wants to merge 6 commits into
CodeYourFuture:mainfrom
khaliun-dev:sprint-2/book-library

Conversation

@khaliun-dev

Copy link
Copy Markdown

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

  • Fixed books not rendering on page load
  • Fixed error when submitting a new book
  • Fixed author being saved as the title
  • Fixed broken delete buttons
  • Fixed incorrect read status
  • Added validation for missing author
  • Clear the form after successfully adding a book

Testing

  • Tested adding books
  • Tested missing fields
  • Tested read/unread status
  • Tested deleting books
  • Checked browser console for error

Questions

None.

@khaliun-dev khaliun-dev added 📅 Sprint 2 Assigned during Sprint 2 of this module 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 11, 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.

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.

@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 11, 2026
@khaliun-dev

Copy link
Copy Markdown
Author

@cjyuan i have made some improvements to the code from the general feedback, specifically:

Changes

  • Fixed book rendering on page load.
  • Fixed book submission and author handling.
  • Fixed Delete functionality.
  • Fixed Read/No status.
  • Added validation for missing fields.
  • Clear the form after adding a book.
  • Improved data types by storing pages as numbers.
  • Improved DOM variable naming.
  • Replaced innerHTML with textContent.
  • Removed unnecessary button IDs.
  • Simplified Read/No logic.
  • Used const where variables aren't reassigned.

Testing

Tested adding, validating, displaying, toggling Read/No, deleting books, and clearing the form. Browser console checked with no errors.

@khaliun-dev khaliun-dev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 12, 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.

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

Comment thread debugging/book-library/index.html Outdated
Comment on lines 49 to 55

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.

  • Even though this element has a required attribute, the user could still "submit" the input the even if this input field is empty. Could you find out why and then address the issue?

  • If possible, also make this input field to accept only positive whole numbers.

Comment thread debugging/book-library/index.html Outdated
Comment on lines 56 to 63

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 checkbox is not showing.

The issue is related to Bootstrap 4.4.1. Could you use AI to find a way to fix the issue? Mentioning "Bootstrap 4.4.1" might help.

Comment thread debugging/book-library/index.html Outdated
value="Submit"
class="btn btn-primary"
onclick="submit();"
onclick="addBook();"

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 research the trade-off between

  1. Attaching event listener in HTML
  2. Attaching event listener using addEventListener() in JS

Comment thread debugging/book-library/script.js Outdated

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.

Can we declare myLibrary in a way that prevents it from being accidentally reassigned?

Comment thread debugging/book-library/script.js Outdated
Comment on lines +40 to +45
const book = new Book(
titleInput.value,
authorInput.value,
Number(pagesInput.value),
readInput.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.

  • What if the input contains leading and trailing space characters?

  • Could Number(pagesInput.value) evaluates to an invalid page count? What numbers should be considered "invalid page count"?

Note: A better and safer approach to deal with user input is to first preprocess/sanitise them, and then store the cleaned values in variables. Thereafter, refer only to the variables for cleaned values consistently throughout the rest of the code.

Comment thread debugging/book-library/script.js Outdated
Comment on lines +49 to +52
titleInput.value = "";
authorInput.value = "";
pagesInput.value = "";
readInput.checked = false;

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.

Note: If the input elements are inside a <form> element, we could also just call a form method to reset the form.

Comment thread debugging/book-library/script.js Outdated
Comment on lines 65 to 70
const rowsNumber = table.rows.length;


for (let n = rowsNumber - 1; n > 0; n--) {
table.deleteRow(n);
}

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.

Clearing a table by deleting its rows row by row is not efficient. Could you look up a more efficient way to clear a table (the <tbody> part of the table)?

Comment thread debugging/book-library/script.js Outdated
Comment on lines 112 to 114
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();

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 alert message is shown before the book is actually deleted; the deletion only occurs after the alert dialog is dismissed. This introduces a risk that the operation may not complete (e.g., if the user closes the browser before dismissing the alert).

In general, it’s better to display a confirmation message only after the associated operation has successfully completed.


alert() is a blocking function call. As a result, invoking it prevents the browser from updating the UI until the dialog is dismissed.

If time permits, research for approaches that allows the UI to update before displaying the alert dialog. (This is an optional change).

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 12, 2026
@khaliun-dev khaliun-dev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 12, 2026
@khaliun-dev

Copy link
Copy Markdown
Author

@cjyuan I have addressed all the comments you have made. Thanks.

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

Changes look good. Well done.

library.push(book);
render();
}
const bookForm = document.getElementById("bookForm");

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

Comment on lines +23 to +26
const titleInput = document.getElementById("title");
const authorInput = document.getElementById("author");
const pagesInput = document.getElementById("pages");
const readInput = document.getElementById("check");

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.

Common practice is to declare all shared variables/constants at the beginning of the files, before function definitions. Doing so makes locating them easier.

Comment on lines +43 to +45
!Number.isFinite(pages) ||
pages < 1 ||
!Number.isInteger(pages)

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 figure out which check is redundant?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the code on line 43, due to another code preventing invalid values anyway.

Comment thread debugging/book-library/script.js Outdated
myLibrary.splice(i, 1);
render();

alert(`You've deleted title: ${deletedTitle}`);

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.

alert() is a blocking function call. As a result, invoking it prevents the browser from updating the UI until the dialog is dismissed.

If time permits, research for approaches that allows the UI to update before displaying the alert dialog. (This is an optional change).

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Aug 13, 2026
Change alert to use setTimeout for better UX.
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. Module-Data-Flows The name of the module. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants