-
-
Notifications
You must be signed in to change notification settings - Fork 120
Glasgow| 25-ITP-May |Bassam Alshujaa| Sprint 2 | book library #291
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
Have you tried looking up "How to change base branch in a PR on GitHub" ? |
Thanks so much for your help, I've looked up to this and I edited it, Thanks again! |
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.
- According to https://validator.w3.org/, there are errors in your
index.html
. Can you fix these errors?
debugging/book-library/script.js
Outdated
pages.value == "" | ||
) { | ||
alert("Please fill all fields!"); | ||
return false; | ||
} else { | ||
let book = new Book(title.value, title.value, pages.value, check.checked); | ||
library.push(book); | ||
let book = new Book(title.value, title.value, 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.
- The input string values could contain only space characters or leading/trailing space characters.
- Page input could be negative or a string that resembles an invalid integer.
debugging/book-library/script.js
Outdated
document.querySelectorAll('.form-group input').forEach(input => { | ||
if (input.type !== 'submit' && input.type !== 'checkbox') { | ||
input.value = ''; | ||
} | ||
}); |
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 reset also the checkbox?
-
Could also consider using
.reset()
method of form.
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; | ||
changeBut.textContent = 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 81–87 as a single statement?
Thanks for your feedback, I'll work on that. |
I've fixed the issues in html and improved the code in js file. Thank you for taking the time to review my work! |
debugging/book-library/script.js
Outdated
if ( | ||
titleInput.value.trim() == '' || | ||
authorInput.value.trim() == '' || | ||
pagesInput.value.trim() == '' | ||
) { | ||
alert("Please fill all fields!"); | ||
return false; | ||
} else { | ||
const pagesNum = Number(pagesInput.value.trim()); | ||
if (!Number.isInteger(pagesNum) || pagesNum <= 0) { | ||
alert("Please enter a valid, positive number of pages."); | ||
return false; | ||
} | ||
let book = new Book(titleInput.value, authorInput.value, parseInt(pagesInput.value), readCheckbox.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.
-
Please note that the raw title and author input could contain leading and trailing space characters.
debugging/book-library/script.js
Outdated
const rows = tbody.rows; | ||
for (let i = rows.length - 1; i >= 0; i--) { | ||
tbody.deleteRow(i); | ||
} |
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 clear the content of <tbody>
using only one operation.
Thanks for your review, I've improved the |
Changes look great. Well done. |
Learners, PR Template
Self checklist
Changelist
I've debugged the script.js file
Questions
Ask any questions you have for your reviewer.