Skip to content

ZA | 25-ITP-May | Malusi Skunyana | Data Flows | Book Library #296

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 5 commits into
base: main
Choose a base branch
from

Conversation

MalusiS
Copy link

@MalusiS MalusiS commented Aug 11, 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

Summary

This PR fixes all known bugs in the Book Library project so it meets the specified requirements:

  • View a list of books on page load
  • Add books with title, author, pages, and read status
  • Prevent adding books if any required fields are missing
  • Delete books from the list
  • Correctly toggle and display read status

Changes by File

index.html:

  • Fixed invalid input types for title and author (type="text" instead of non-standard types).
  • Removed empty value from checkbox and used check.checked in JS.
  • Changed onclick="submit();" to onclick="addBook();" to avoid conflict with the built-in submit() method.
  • Removed placeholder empty in table for cleaner rendering.

script.js:

  • Fixed incorrect variable reference (library → myLibrary).
  • Corrected author assignment in addBook() (used author.value instead of title.value).
  • Fixed syntax error in render() loop for deleting rows.
  • Corrected “Read” status logic to match boolean check value.
  • Fixed variable naming (delButton vs delBut).
  • Corrected event type (click instead of clicks).
  • Renamed submit() to addBook() for clarity and to avoid conflicts.
  • Added clearForm() function to reset inputs after adding a book.
  • Minor cleanup for readability and maintainability.

Questions

Ask any questions you have for your reviewer.

…ubmit() call to addBook(), remove placeholder table row
…r() loop syntax, repair delete button event, correct read status logic, rename submit() to addBook(), clear form after add
@MalusiS MalusiS added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 11, 2025
@MalusiS MalusiS changed the title ZA | 25-ITP-May | Malusi Skunyana | Data Flows | Book library ZA | 25-ITP-May | Malusi Skunyana | Data Flows | Book Library Aug 11, 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.

  • 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 11, 2025
@MalusiS MalusiS changed the base branch from book-library to main August 11, 2025 19:30
@MalusiS MalusiS 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 11, 2025
@MalusiS
Copy link
Author

MalusiS commented Aug 11, 2025

@cjyuan, I have changed the base branch to CYF's main. I have also made improvements to my code as per the general feedback you referred me to. Thank you so much for the great feedback.

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

Comment on lines +23 to +39
titleInput.value.trim() === "" ||
authorInput.value.trim() === "" ||
pagesInput.value.trim() === ""
) {
alert("Please fill all fields!");
return false;
} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
render();
return;
}

if (!Number.isInteger(Number(pagesInput.value)) || Number(pagesInput.value) <= 0) {
alert("Pages must be a positive number.");
return;
}

let book = new Book(
titleInput.value.trim(),
authorInput.value.trim(),
Number(pagesInput.value),
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.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you, CJ. I really appreciate the great feedback.

Comment on lines +47 to 52
function clearForm() {
titleInput.value = "";
authorInput.value = "";
pagesInput.value = "";
readCheckbox.checked = false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If the input elements are enclosed inside a <form>, we could also clear them by calling the .reset() method of the form element.

@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 11, 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants