Skip to content

London | 26-ITP-Jan | Angela McLeary | Sprint 2 | Book Library#415

Open
AngelaMcLeary wants to merge 30 commits intoCodeYourFuture:mainfrom
AngelaMcLeary:feature/book-library
Open

London | 26-ITP-Jan | Angela McLeary | Sprint 2 | Book Library#415
AngelaMcLeary wants to merge 30 commits intoCodeYourFuture:mainfrom
AngelaMcLeary:feature/book-library

Conversation

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

Debugging of book library app and fixing typos, syntaxes and validation to mention a few.

@AngelaMcLeary AngelaMcLeary added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 9, 2026
Copy link
Copy Markdown
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.

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 Apr 10, 2026
@AngelaMcLeary AngelaMcLeary added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 12, 2026
function populateStorage() {
if (myLibrary.length == 0) {
let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true);
let book1 = new Book("Robinson Crusoe", "Daniel Defoe", "252", true);
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.

Did you notice the third parameter is a string and not a number?

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.

Hi @cjyuan, Thanks for your feedback. I did not notice that, thanks for pointing it out. Since the input is a string, I have converted the pages to numbers.

if (
title.value == null ||
title.value == "" ||
author.value == null ||
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.

Why compare .value to null? When will .value ever be null?

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.

Hi @cjyuan, Thank you for your feedback. You are right, .value is never null. It returns a string or "" when empty. So that check was unnecessary. I have also refactored that code block and removed the unnecessary checks.

} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
let book = new Book(title.value, author.value, pages.value, 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.

Using raw input value without properly pre-processing them is dangerous.

Here are some input that can "mess up" the app:

 title.value = "                       ";
 page.value = "3e-2";

@@ -1 +1 @@
let myLibrary = [];
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.

Your latest commit changed const back to let.

It's a good practice to click the "File changes" in your own PR to review (double check) the code your submitted.

Image

Comment on lines +88 to +94
let readStatus = "";
if (myLibrary[i].check == false) {
readStatus = "Yes";
} else {
readStatus = "No";
} else {
readStatus = "Yes";
}
changeBut.innerText = readStatus;
changeBtn.innerText = readStatus;
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 could be a good opportunity to practice using the ? : conditional operator. Can you rewrite the code on lines 88–94 as a single statement?

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.

Hi @cjyuan, Thank you for your feedback. Good suggestion — I’ve replaced the if statement with a ternary operator for a cleaner single-line expression.

delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
let deleteBtn = document.createElement("button");
deleteBtn.id = i + 5;
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.

  • Lines 85, 103:
    • Are the values assigned to these id attributes unique?
    • Is there any need to assign an id attribute to either buttons?

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.

Hi @cjyuan, Thank you for your feedback. Good point - the id attributes were based on the loop index, so they are not guaranteed to be unique after deletions. Also since I'm not using them for DOM selection, so they are unnecessary, so I've removed both (changeBtn.id and delete.id).

deleteCell.appendChild(deleteBtn);
deleteBtn.className = "btn btn-warning";
deleteBtn.innerHTML = "Delete";
deleteBtn.addEventListener("click", function (index) {
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.

Why introduce the parameter index to the callback function?

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.

Hi @cjyuan, Thank you for your feedback. That is definitely a mistake on my part. Furthermore the callback doesn't receive a custom index, only the event object. I wasn't even using it, I've deleted it. I have also refactored the code.

Comment on lines 108 to 110
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.

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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