-
-
Notifications
You must be signed in to change notification settings - Fork 120
London | ITP-May-2025 | Hibo Sharif | Module-Data-Group | Sprint2 | Book Library #249
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 | Hibo Sharif | Module-Data-Group | Sprint2 | Book Library #249
Conversation
-I added trim() to remove extra whitespaces in both ends when extra spaces added incorrectly to the form.
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!
titleEl.value.trim() === "" || | ||
authorEl.value.trim() === "" || | ||
pagesEl.value.trim() === "" | ||
|
||
) { | ||
alert("Please fill all fields!"); | ||
return false; | ||
} else { | ||
let book = new Book(title.value, author.value, pages.value, check.checked); | ||
} | ||
let pageCount = parseInt(pagesEl.value.trim()); | ||
if (pageCount <= 0 || isNaN(pageCount)) { | ||
alert("Please enter a valid page number"); | ||
return false; | ||
} | ||
let book = new Book( | ||
titleEl.value.trim(), | ||
authorEl.value.trim(), | ||
pageCount, | ||
checkEl.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 book = new Book(cleanTitle, cleanAuthor, pageCount, checkEl.checked);
Self checklist
Changelist
-Ensured the table clears properly before re-rendering
Questions
Ask any questions you have for your reviewer.