Skip to content

London | 26-ITP-May | Damilola Odumosu | Sprint 2 | Book Library - #533

Open
d-odumosu wants to merge 1 commit into
CodeYourFuture:mainfrom
d-odumosu:book-library
Open

London | 26-ITP-May | Damilola Odumosu | Sprint 2 | Book Library#533
d-odumosu wants to merge 1 commit into
CodeYourFuture:mainfrom
d-odumosu:book-library

Conversation

@d-odumosu

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

@d-odumosu d-odumosu added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 2 Assigned during Sprint 2 of this module Module-Data-Flows The name of the module. labels Aug 9, 2026
Comment on lines 48 to 53
class="form-control"
id="pages"
name="pages"
min="1"
required
/>

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 find out why the browser does not check if the value in this input field is a positive whole number (even if when the constraints min="1" is specified)?

type="submit"
value="Submit"
class="btn btn-primary"
onclick="submit();"

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 find out the tradeoff between
A) specifying a callback via an onclick attribute in HTML, and
B) specifying a callback in JavaScript

?

@@ -1,103 +1,101 @@
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.

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

Comment on lines +42 to +47
let book = new Book(
titleInput.value,
authorInput.value,
Number(pagesInput.value),
checkInput.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.

  • Is Number(pagesInput.value) always a valid positive whole number?

  • The code checks the trimmed value but it uses the raw values.

    A better and safer approach to deal with user input is to first store the preprocessed input in variables, validate them, then use those cleaned values consistently throughout the rest of the code.

Comment on lines +28 to +31
const titleInput = document.getElementById("title");
const authorInput = document.getElementById("author");
const pagesInput = document.getElementById("pages");
const checkInput = 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 file before function definitions.

});
}

const tableBody = document.querySelector("tbody");

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 not keep this variable declaration with the other variable declarations at the beginning of the file?

}

const tableBody = document.querySelector("tbody");
let 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.

Does readStatus need to be shared among functions? If not, it is better to declare it as a local variable in the function where it is used.

Comment on lines +86 to +91
if (!book.check) {
readStatus = "No";
} else {
readStatus = "Yes";
}
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. Could you rewrite the code on lines 86–91 as a single statement?

Comment on lines +97 to +99
alert(`You've deleted title: ${book.title}`);
myLibrary.splice(index, 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.

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

Suggestion: Research for approaches that allows the UI to update before displaying the alert dialog.

@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 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Data-Flows The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants