-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
base: main
Are you sure you want to change the base?
London | ITP-May-2025 | Mo Muchunu | Module-Data-Flows | Sprint 2 | Book Library #243
Conversation
3c0fb60
to
8ddf6f9
Compare
8ddf6f9
to
0e6cabf
Compare
There was a problem hiding this 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.
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) |
There was a problem hiding this comment.
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.
title.value == null || // Clear form fields after successful submission | ||
title.value == "" || | ||
author.value == null || | ||
author.value == "" || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Can
.value
benull
? (Do we need to checksomeInputElement.value == null
?) -
Are these checks still needed?
const book = new Book(title.value, author.value, pages.value, check.checked); // Correct 'author' key | ||
myLibrary.push(book); // Correct array name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (let n = rowsNumber - 1; n > 0; n--) { // Add missing closing bracket | ||
table.deleteRow(n); | ||
} |
There was a problem hiding this comment.
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?
titleCell.innerHTML = myLibrary[i].title; | ||
authorCell.innerHTML = myLibrary[i].author; | ||
pagesCell.innerHTML = myLibrary[i].pages; |
There was a problem hiding this comment.
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
.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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?
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) |
There was a problem hiding this comment.
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
?
Learners, PR Template
Self checklist
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