London | 26-ITP-May | Dipa Sarker | Sprint 2 | Book Library Project - #521
London | 26-ITP-May | Dipa Sarker | Sprint 2 | Book Library Project#521Dipa-Sarker wants to merge 3 commits into
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Can you check if any of this general feedback can help you further improve your code?
https://github.com/CodeYourFuture/Module-Data-Flows/blob/general-review-feedback/debugging/book-library/feedback.md
Doing so can help me speed up the review process. Thanks.
|
Thank you for giving me the general feedback file. I made correction according to this. |
cjyuan
left a comment
There was a problem hiding this comment.
Changes look solid. I just have a few suggestions.
| @@ -1,17 +1,18 @@ | |||
| let myLibrary = []; | |||
There was a problem hiding this comment.
Can we declare myLibrary in a way that prevents it from being accidentally reassigned?
There was a problem hiding this comment.
we can use const instead of let.
| const titleInput = document.getElementById("title"); //rename all variable names | ||
| const authorInput = document.getElementById("author"); | ||
| const pagesInput = document.getElementById("pages"); | ||
| const checkInput = document.getElementById("check"); | ||
| const bookForm = document.getElementById("bookForm"); |
There was a problem hiding this comment.
Note: Normal practice is to keep variable/constant declaration at beginning of the file (before function definition).
There was a problem hiding this comment.
okay, moved all the variables at the very beginning.
| bookForm.addEventListener("submit", function (event) { //after user submits the book form | ||
| // this will run submit () function to add book | ||
| event.preventDefault(); | ||
| submit(); | ||
| }); |
There was a problem hiding this comment.
Common practice is to keep all the "code that runs once on page load" in the same place (e.g., in a function named init() or setup()) and then call the function on page load.
Code that setups event listener usually fall into this category.
|
|
||
| changeBut.addEventListener("click", function () { | ||
| const changeButton = document.createElement("button"); //correct changeBut > changeButton | ||
| changeButton.id = i; |
There was a problem hiding this comment.
Is there any need to assign an id attribute to this element?
In addition, "0", "1", ..., do not make good ID value.
There was a problem hiding this comment.
ok, we don't need button id, because we have event listener to response with change button. Besides, only id ="0", "1",...etc don't mean anything. I deleted this line.
| const deletedTitle = myLibrary[i].title; //save the book title which should have to delete | ||
| myLibrary.splice(i, 1); | ||
| render(); | ||
| alert(`You've deleted title: ${deletedTitle}`); |
There was a problem hiding this comment.
alert() is a blocking function call. As a result, invoking it prevents the browser from updating the UI until the dialog is dismissed.
If time permits, research for approaches that allows the UI to update before displaying the alert dialog. (This is an optional change).
There was a problem hiding this comment.
Ok, I got your point. I did two things.
- Use confirm() before deleting.
- Put a normal message element in the HTML instead of using alert() after deletion.
cjyuan
left a comment
There was a problem hiding this comment.
Changes look good. Well done.
| /*window.addEventListener("load", function () { | ||
| //delete e as it is never used | ||
| populateStorage(); | ||
| render(); | ||
| }); | ||
| }); */ |
There was a problem hiding this comment.
In practice, it is better to remove any unused code instead of wrap them in a comment in order to keep the code clean.
| const confirmed = confirm( //use confirm () to handle popup message for ok/cancel | ||
| `Are you sure you want to delete "${deletedTitle}"?` | ||
| ); |
|
Thank you for your feedback! |
Learners, PR Template
Self checklist
Changelist
Changes made
Testing
The changes were tested locally and the application is working as expected.