Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Responsive Intro section with dropdown navigation using mobile first

Nicolas 90

@byNico1

Desktop design screenshot for the Intro section with dropdown navigation coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

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

@akpekig

Posted

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 helpful

2

Nicolas 90

@byNico1

Posted

@akpekig thanks I did that and probably could have improved my code more, but already made the JavaScript better

0
wannacode 680

@kwngptrl

Posted

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 helpful

0

Nicolas 90

@byNico1

Posted

@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 GitHub
Discord logo

Join 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