Skip to content

London | ITP-May-2025 | Mo Muchunu | Module-Data-Flows | Sprint 2 | Book Library #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Mo-Muchunu
Copy link

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

  • Fixed rendering bug that prevented books from displaying on page load.

  • Corrected input handling to prevent missing values.

  • Improved form validation and reset inputs after submission.

  • Fixed broken delete functionality and removed placeholder rows for cleaner display.

Questions

@Mo-Muchunu Mo-Muchunu force-pushed the Sprint-2/feature/book-library branch from 3c0fb60 to 8ddf6f9 Compare July 27, 2025 06:48
@Mo-Muchunu Mo-Muchunu force-pushed the Sprint-2/feature/book-library branch from 8ddf6f9 to 0e6cabf Compare July 27, 2025 07:02
@Mo-Muchunu Mo-Muchunu added the Needs Review Participant to add when requesting review label Jul 27, 2025
@cjyuan cjyuan added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Aug 2, 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.

  • Good job in fixing the errors in the HTML file.

  • Code is working good. I just have a bunch of suggestions.

Comment on lines +36 to +38
authorValue.length < minLength ||
!/^(?=(?:.*[A-Za-z]){3,})[A-Za-z ]+$/.test(titleValue) || // Validate input for minimum length and character type
!/^(?=(?:.*[A-Za-z]){3,})[A-Za-z ]+$/.test(authorValue)
Copy link
Contributor

Choose a reason for hiding this comment

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

  • These rules seem to be a bit restrictive. A lot of book titles have digits or symbols like "&", ",", "-".

  • The indentation level of this if-block is off.

Comment on lines +45 to +48
title.value == null || // Clear form fields after successful submission
title.value == "" ||
author.value == null ||
author.value == "" ||
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Can .value be null? (Do we need to check someInputElement.value == null?)

  • Are these checks still needed?

Comment on lines +55 to +56
const book = new Book(title.value, author.value, pages.value, check.checked); // Correct 'author' key
myLibrary.push(book); // Correct array name
Copy link
Contributor

Choose a reason for hiding this comment

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

  • With the current check, the page number shown in this screenshot is possible.
image
  • The title and author may contain leading and trailing space characters.

  • Should the page number be stored as a string or as a number

Comment on lines +77 to 79
for (let n = rowsNumber - 1; n > 0; n--) { // Add missing closing bracket
table.deleteRow(n);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of deleting the table rows one by one, can you think of a more efficient way to remove all rows (except the <th>...</th>) in the table?

Comment on lines 89 to 91
titleCell.innerHTML = myLibrary[i].title;
authorCell.innerHTML = myLibrary[i].author;
pagesCell.innerHTML = myLibrary[i].pages;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that when setting the text content of an HTML element, there are subtle but important differences between using .innerHTML, innerText, and textContent.

Comment on lines 98 to +99
let readStatus = "";
if (myLibrary[i].check == false) {
readStatus = "Yes";
} else {
readStatus = "No";
}
readStatus = myLibrary[i].check ? "Yes" : "No"; // Correct read status logic for not read
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also write

const readStatus = myLibrary[i].check ? "Yes" : "No";


delButton.addEventListener("click", function () { // Click not clicks
const index = parseInt(this.getAttribute("data-index"), 10); // Get index from button's data attribute and convert from string to number (base 10)
if (confirm(`You're about to delete "${myLibrary[index].title}". Continue?`)) { // Require user confirmation before deletion
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice touch in changing alert to confirm!

alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
const delButton = document.createElement("button");
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you notice that the two variables, changeBut and delButton, use different naming conventions?

Comment on lines +108 to +114
delButton.className = "btn btn-warning"; // Correct delButton variable name
delButton.innerHTML = "Delete";
delButton.setAttribute("data-index", i); // Add data attribute to identify the book index
deleteCell.appendChild(delButton);

delButton.addEventListener("click", function () { // Click not clicks
const index = parseInt(this.getAttribute("data-index"), 10); // Get index from button's data attribute and convert from string to number (base 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use "data-index" attribute to store the index with delButton, but not with changeBut?

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Aug 2, 2025
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants