-
-
Notifications
You must be signed in to change notification settings - Fork 158
Glasgow | 25-ITP-Sep |Mohammed Abdoon| Sprint 2 | book library #343
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?
Conversation
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.
There are some debugging code left in script.js. Can you remove it to keep the code clean?
debugging/book-library/script.js
Outdated
| let titleInput = document.getElementById("title").value; | ||
| let authorInput = document.getElementById("author").value.trim(); | ||
| const pagesInput = Number(document.getElementById("pages").value.trim()); | ||
| const checkBtn = document.getElementById("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.
- Title may also contain leading/trailing space.
- The first three variables are assigned the input values (and not DOM elements). Why not do the same to the 4th variable?
- Note:
Number()ignores leading/trailing space in a string, sotrim()is optional on line 31.
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 first three variables store the current input values because we need them directly, while the checkBtn is only needed to attach a click event to it, not it's value. so that's why I handled it differently.
| titleInput = titleInput.replace(/</g, ""); | ||
| authorInput = authorInput.replace(/</g, ""); |
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.
What if a book title really contains a "<" character?
Why only remove '<' and not all "special characters" that may be misinterpreted as part of HTML code?
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 thought only '<' could be misinterpreted as part of HTML.
I removed the validation completely and used .textContent instead of .innerHTML when assigning the input to the new object, so the page is not affected when displaying the text.
| authorInput = authorInput.replace(/</g, ""); | ||
|
|
||
| console.log(titleInput); | ||
| if ( titleInput == "" || authorInput == "" || pagesInput == "" ) { |
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 compare pagesInput to ""?
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.
To make sure whether the input isn't empty or not.
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.
pagesInput is a number.
debugging/book-library/script.js
Outdated
| titleCell.innerHTML = myLibrary[i].title; | ||
| authorCell.innerHTML = myLibrary[i].author; |
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.
By assigning a value to .innerHTML, some "special characters" in the book title may be misinterpreted as part of HTML code.
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. I used .textContent instead so we ignore any special characters.
debugging/book-library/script.js
Outdated
| let readStatus = ""; | ||
| if (myLibrary[i].check == false) { | ||
| if (myLibrary[i].check == true) { | ||
| readStatus = "Yes"; | ||
| } else { | ||
| readStatus = "No"; | ||
| } | ||
| changeBut.innerText = readStatus; | ||
| changeButton.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.
It is possible to simplify the code on lines 83-89 into one or two lines of code. As a challenge, can you simplify it?
I just modified the code and made the required changes. Thank you. |
|
Changes look good. |
Learners, PR Template
Self checklist
Changelist
finished book library exercise.
Questions
No questions so far. Thank you.