-
-
Notifications
You must be signed in to change notification settings - Fork 161
GLASGOW | May-2025 | Taras Mykytiuk | Sprint 2 | Book library #311
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
Conversation
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Module-Data-Flows) doesn't match expected format (example: 'Sprint 2', without quotes) |
3 similar comments
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Module-Data-Flows) doesn't match expected format (example: 'Sprint 2', without quotes) |
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Module-Data-Flows) doesn't match expected format (example: 'Sprint 2', without quotes) |
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Module-Data-Flows) doesn't match expected format (example: 'Sprint 2', without quotes) |
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Module-Data-Flows) doesn't match expected format (example: 'Sprint 2', without quotes) |
1 similar comment
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Module-Data-Flows) doesn't match expected format (example: 'Sprint 2', without quotes) |
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Wrong number of parts separated by |s |
cjyuan
left a comment
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 you check if any of this general feedback can help you further improve your code?
https://github.com/cjyuan/Module-Data-Flows/blob/book-library-feedback/debugging/book-library/feedback.md
Doing so can help me speed up the review process. Thanks.
…e-Data-Flows into book_library update branch after review
|
Hi. Now I have taken feedback.md into account. |
debugging/book-library/script.js
Outdated
| function populateStorage() { | ||
| if (myLibrary.length == 0) { | ||
| let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); | ||
| let book1 = new Book("Robison Crusoe", "Daniel Defoe", Number("252"), true); |
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 not just use the numeric literal 252?
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.
Just did not think about it)
debugging/book-library/script.js
Outdated
| const div = document.createElement('div'); | ||
| div.textContent = str; | ||
| return div.innerHTML; |
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.
This turns special characters to HTML entities. For example, > to >.
Have you checked what would happen if you include a character & in the title?
You can ask AI why this conversion is not needed when the input is assigned to the .textContent or .innerText properties.
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.
Thanks. Now I will consider this in future.
| function isHexadecimal(input) { | ||
| return /^0x[0-9a-fA-F]+$/.test(input); | ||
| } |
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 would you want to allow the user to enter a page count as a hexadecimal number?
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.
I dont allow. When user try to input something like: "0x10" - this function return true and condition in line 50 trigger error alert window in line 53.
debugging/book-library/script.js
Outdated
| bookTitleInput.value.trim() == "" || | ||
| bookAuthorInput.value.trim() == "" || | ||
| bookNumberOfPagesInput.value.trim() == "" | ||
| ) { | ||
| alert("Please fill all fields!"); | ||
| return false; | ||
| } else { | ||
| let book = new Book(title.value, author.value, pages.value, check.checked); | ||
| } else if ( | ||
| isNaN(Number(bookNumberOfPagesInput.value.trim())) || | ||
| !isValidInteger(Number(bookNumberOfPagesInput.value.trim())) || | ||
| isHexadecimal(bookNumberOfPagesInput.value.trim()) || | ||
| Number(bookNumberOfPagesInput.value.trim()) <= 0 | ||
| ) { | ||
| alert("Invalid number of pages format!"); | ||
| return false; | ||
| } else { | ||
| const bookTitle = sanitizeInput(bookTitleInput.value.trim()); | ||
| const bookAuthor = sanitizeInput(bookAuthorInput.value.trim()); | ||
| const bookNumberOfPages = parseInt(sanitizeInput(bookNumberOfPagesInput.value.trim()), 10); | ||
| let book = new Book(bookTitle, bookAuthor, bookNumberOfPages, isBookReadCheckBox.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.
-
Number.isInteger()would also returnfalsewhen the input is not a number; we can omitisNaN()check.
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.
Yes. Now is more efficient.
| let readStatus = ""; | ||
| if (myLibrary[i].check == false) { | ||
| readStatus = "No"; | ||
| } else { | ||
| readStatus = "Yes"; | ||
| } | ||
| changeBut.innerText = readStatus; | ||
| changeReadStatusButton.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.
This could be a good opportunity to practice using the ? : conditional operator. Can you rewrite the code on lines 99-105 as a single statement?
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.
Thank. I just missed it.
cjyuan
left a comment
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 good.
| <input | ||
| type="number" | ||
| type="text" | ||
| class="form-control" | ||
| id="pages" | ||
| name="pages" | ||
| required | ||
| /> |
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 change type="number" to type="text" when Page count is supposed to be an integer? If anything, we should make the check stricter (to allow only digits in the input field).
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.
)) Yes. Now fixed.
debugging/book-library/script.js
Outdated
| readStatus = "No"; | ||
| } | ||
| changeBut.innerText = readStatus; | ||
| !myLibrary[i].check ? readStatus = "No" : readStatus = "Yes"; |
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 common way to use ? : is
readStatus = !myLibrary[i].check ? "No" : "Yes";
!myLibrary[i].check ? "No" : "Yes" is an expression that evaluates to either "No" or "Yes".
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.
Changed.
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.
Thanks for review!
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
In this branch was performed bugfixing of Book library app.
Questions
Ask any questions you have for your reviewer.