-
-
Notifications
You must be signed in to change notification settings - Fork 117
London| ITP-May-2025| Zohreh Kazemianpour |Book library #252
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: book-library
Are you sure you want to change the base?
London| ITP-May-2025| Zohreh Kazemianpour |Book library #252
Conversation
- Add event listener for submit button instead of HTML onclick - Prevent default form submission behavior - Correct array name from 'library' to 'myLibrary' - Call render() after adding new books to update display - Fix validation to check for empty author field
- Reset title, author, and pages input fields to empty strings
debugging/book-library/script.js
Outdated
let book = new Book(title.value, title.value, pages.value, check.checked); | ||
library.push(book); | ||
render(); | ||
let book = new Book(title.value, author.value, pages.value, check.checked); |
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.
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.
No, I don't think it's a good idea to keep leading and trailing spaces. Thank you for catching this issue! I have now implemented better data validation. I used alert() for consistency here, but I am not sure if it is the best in terms of UX.
debugging/book-library/script.js
Outdated
table.deleteRow(n); | ||
} | ||
//insert updated row and cells | ||
let length = myLibrary.length; | ||
for (let i = 0; i < length; i++) { | ||
let row = table.insertRow(1); | ||
let row = table.insertRow(i+1); |
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 omit the argument in insertRow()
if we wanted to append a row to the table.
debugging/book-library/script.js
Outdated
readStatus = myLibrary[i].check ? "Yes" : "No"; | ||
changeBut.innerText = readStatus; |
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.
The declaration of variable readStatus
was deleted. You could also combined lines 82-83 into one statement without using readStatus
.
debugging/book-library/script.js
Outdated
alert(`You've deleted title: ${myLibrary[i].title}`); | ||
myLibrary.splice(i, 1); | ||
const index = parseInt(this.dataset.index) | ||
myLibrary.splice(index, 1); |
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.
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.
…l tag - Fix meta tag structure (charset and viewport) - Change invalid input types (title/author → text) - Remove trailing slashes from void elements
Hi @cjyuan, thank you so much as always, for the valuable feedback. I have updated the code based on your comments. Could you please review when you have a moment? I appreciate your insights! |
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.
Changes look great! Well done!
) { | ||
alert("Please fill all fields!"); | ||
return false; | ||
} else { | ||
let book = new Book(title.value, author.value, pages.value, check.checked); | ||
} | ||
if (isNaN(parseInt(pages.value)) || parseInt(pages.value) <= 0) { | ||
alert("Please enter a valid positive number for pages!"); | ||
return false; | ||
} | ||
let book = new Book(title.value.trim(), author.value.trim(), parseInt(pages.value), check.checked); |
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 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.
const cleanTitle = title.value.trim();
...
const pageNum = parseInt(pages.value);
...
const book = new Book(cleanTitle, cleanAuthor, pageNum, check.checked);
myLibrary.push(book1); | ||
myLibrary.push(book2); | ||
} | ||
} | ||
} | ||
|
||
const title = document.getElementById("title"); |
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.
Using descriptive and consistent suffixes (like El
, Input
, Btn
, Form
, etc.) for variables that store DOM elements can improve code readability and maintainability.
Thank you so much for the complete label. I appreciate the time and energy you put into reviewing our coursework. |
Learners, PR Template
Self checklist
Changelist
This PR addresses all major functionality bugs in the Book Library:
✔ Fixed book display
Books now render correctly on page load
The default books appear as intended
✔ Corrected form submission
Properly captures all fields (title, author, pages, read status)
Fixed title/author mixup bug
Added validation for required fields
✔ Fixed delete functionality
Delete buttons now work reliably
Uses stable data-index system instead of fragile IDs
✔ Read status accuracy
Correctly saves and displays read/unread state
Toggle buttons update properly
Questions
Ask any questions you have for your reviewer.