Responsive Intro section with dropdown navigation using mobile first
Design comparison
Solution retrospective
I would like a review on my project and knowing how I could improve my JavaScript Code because I know it could be Improved
Community feedback
- @akpekigPosted over 1 year ago
I think your code could be improved by reducing the redundancy. A lot of the elements are selected using specific classes despite having the same functions and events. To solve this, instead of:
const elementOne = document.querySelector(".element1"); const elementTwo = document.querySelector(".element2"); ... const elementN = document.querySelector(".elementN");
give them a unifying class name that can call them all simultaneously:
const elements = document.querySelectorAll(".element");
Then you can write a function that handles the conditional logic and pass it to the array of elements so you aren't writing the same/similar conditionals repeatedly:
function handleEl(el, optionalEl) { ... } elements.forEach(element => { element.addEventListener('click', () => handleEl(element)) });
Marked as helpful2@byNico1Posted over 1 year ago@akpekig thanks I did that and probably could have improved my code more, but already made the JavaScript better
0 - @kwngptrlPosted over 1 year ago
You could improve on the hover states as well. As it is now, your css has no :hover on the links and buttons (the font color is supposed to get darker.) Refer to the style-guide.md.
Marked as helpful0@byNico1Posted over 1 year ago@kwngptrl thanks I actually saw there was a lot of differences between my solution and initial design so already Improved it a lot
0
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