@shakhboz-shukhrat
Posted
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 helpful