Skip to content

Conversation

Bluejay600
Copy link

@Bluejay600 Bluejay600 commented Aug 9, 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 Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

this PR is to View a list of books that I've read Add books to a list of books that I've read, Including title, author, number of pages and if I've read.

Questions

Ask any questions you have for your reviewer.

@Bluejay600 Bluejay600 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 9, 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.

Doing so can help me speed up the review process. Thanks.

  • In addition, can you change the base branch of this PR from CYF's book-library to CYF's main?
image

@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 9, 2025
@Bluejay600 Bluejay600 changed the base branch from book-library to main August 16, 2025 11:38
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Wrong number of parts separated by |s

@Bluejay600 Bluejay600 changed the title Sheffield | May-2025 | Waleed-Yahay Salih-Taha | Book library Sheffield | May-2025 | Waleed-Yahay Salih-Taha | Sprint-2 | Book library Aug 16, 2025
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Sprint part (Sprint-2) doesn't match expected format (example: 'Sprint 2', without quotes)

@Bluejay600 Bluejay600 changed the title Sheffield | May-2025 | Waleed-Yahay Salih-Taha | Sprint-2 | Book library Sheffield | May-2025 | Waleed-Yahay Salih-Taha | Sprint 2 | Book library Aug 16, 2025
@Bluejay600 Bluejay600 changed the title Sheffield | May-2025 | Waleed-Yahay Salih-Taha | Sprint 2 | Book library Sheffield | May-2025 | Waleed-Yahay Salih-Taha | Data Flow Sprint 2 | Book library Aug 16, 2025
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Sprint part (Data Flow Sprint 2) doesn't match expected format (example: 'Sprint 2', without quotes)

@Bluejay600 Bluejay600 changed the title Sheffield | May-2025 | Waleed-Yahay Salih-Taha | Data Flow Sprint 2 | Book library Sheffield | May-2025 | Waleed-Yahay Salih-Taha | Sprint 2 | Book Library Aug 16, 2025
@Bluejay600 Bluejay600 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 16, 2025
@Bluejay600
Copy link
Author

@cjyuan you can now review it, it's ready.

const pages = document.getElementById("pages");
const check = document.getElementById("check");

document.getElementById("submitBtn").addEventListener("click", addBook);
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 better to group all the code that's to be executed once on page load together in the window.onload callback function (around line 4)

Copy link
Author

Choose a reason for hiding this comment

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

now I Grouped all setup code in window.onload

Comment on lines 28 to 33
if (!title.value.trim() || !author.value.trim() || !pages.value.trim()) {
alert("Please fill all fields with valide values (no empty spaces)!");
return;
}
let book = new Book(title.value.trim(), author.value.trim(), pages.value.trim(), check.checked);
myLibrary.push(book);
Copy link
Contributor

Choose a reason for hiding this comment

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

  • For better performance (reduce number of function calls) and reducing the chance of using raw input accidently, we could stored the pre-processed/sanitized/normalized input in some variables first, and reference the variables in other part of the function.

  • pages.value.trim() is a string, without proper validation, sanitization, and pre-processing, the following page numbers are possible:

image

Copy link
Author

Choose a reason for hiding this comment

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

Pre-processed and sanitizes the input before using it multiple times

Comment on lines 72 to 74
alert(`You've deleted title: ${book.title}`);
myLibrary.splice(i, 1);
render();
Copy link
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.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed the delete alert order (show confirmation only after deletion succeeds, not before)

Comment on lines 20 to 21
const pages = document.getElementById("pages");
const check = 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.

Using descriptive and consistent suffixes (like El, Input, Btn, Form, etc.) for variables that store DOM elements can improve code readability and maintainability.

Copy link
Author

Choose a reason for hiding this comment

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

I have Consistented suffixes for DOM elements (El, Btn, Form, etc.)

@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 17, 2025
@Bluejay600 Bluejay600 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 19, 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.

Changes look good.

Comment on lines +5 to +11
const titleInputEl = document.getElementById("title");
const authorInputEl = document.getElementById("author");
const pagesInputEl = document.getElementById("pages");
const readCheckEl = document.getElementById("check");
const submitBtnEl = document.getElementById("submitBtn");
const bookFormEl = document.getElementById("bookForm");
const tbodyEl = document.querySelector("#display tbody");
Copy link
Contributor

Choose a reason for hiding this comment

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

These set of code could be made an exception and place outside window.onload.
Otherwise, the declared variables can only be accessed locally within the callback function.

alert("Author must be at least 2 characters long.");
return;
}
const pageNum = Number(pages);
Copy link
Contributor

Choose a reason for hiding this comment

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

If you place this line of code at the beginning of this function, you could then reference the value of this variable at lines 37.

Comment on lines +50 to 60
if (!Number.isInteger(pageNum) || pageNum <= 0 || pageNum > 10000) {
alert("Pages must be a positive whole number (1–10,000).");
return;
}

function render() {
let table = document.getElementById("display");
let rowsNumber = table.rows.length;
//delete old table
for (let n = rowsNumber - 1; n > 0; n-- {
table.deleteRow(n);
// Add book
let book = new Book(title, author, pages, read);
myLibrary.push(book);
render();
bookFormEl.reset();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use the VSCode extension prettier to auto format/indent the code?

@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 Aug 19, 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. Module-Data-Flows The name of the module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants