Design comparison
Solution retrospective
This is my solution for the Notifications Page.
It was overall easy and enjoyable building this project.
I would appreciate your feedback and would like to receive your comments and perspectives regarding the project. Thanks a lot!
Community feedback
- @shakhboz-shukhratPosted over 1 year ago
Hello there!!!
There are no glaring issues with the code. However, there are some improvements that could be made to the readability and performance of the code:
Instead of using "querySelectorAll" to select all unread marks, it is better to use "getElementsByClassName" if all unread marks share a class name.
It is better to store the length of the "messages" array in a separate variable rather than calling ".length" multiple times.
Here is the updated code:
const totalNotifications = document.querySelector(".notifications-number"); const readBtn = document.querySelector(".read-btn"); const messages = document.getElementsByClassName("message"); const unreadMarks = document.getElementsByClassName("unread-mark"); const messageCount = messages.length;
readBtn.addEventListener("click", () => { for (let i = 0; i < messageCount; i++) { messages[i].classList.remove("unread"); } totalNotifications.innerHTML = "0"; });
You did a very good job! Happy coding!
Marked as helpful0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord