Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 7 months ago

FAQ Accordion

CoolNight99•440
@CoolNight99
A solution to the FAQ accordion challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

I think I got the design and functionality accurate to the assignment.

What challenges did you encounter, and how did you overcome them?

I mainly encountered challenges with syncing up the plus icon changing to minus and the FAQ answer being visible. I was able to do it after some trial and error.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Aakash Verma•9,520
    @skyv26
    Posted 7 months ago

    Hello @CoolNight99,

    Great work on the implementation! 👏 Here are some suggestions to improve your code and styling:


    JavaScript Code Feedback 💡

    1. Code Compactness and Readability 🧹:

      • Consider using functions to encapsulate repeated logic (e.g., toggling FAQ visibility). This will reduce redundancy and improve readability.

      • Here's a simplified version of your click and keypress handlers:

        const toggleFAQ = (faqAnswer, plusIcon) => {
            const isVisible = window.getComputedStyle(faqAnswer).display !== "none";
            faqAnswer.style.display = isVisible ? "none" : "block";
            plusIcon.src = isVisible
                ? "./assets/images/icon-plus.svg"
                : "./assets/images/icon-minus.svg";
        };
        
        faqQuestionDivs.forEach((faqQuestionDiv) => {
            const plusIcon = faqQuestionDiv.querySelector(".plus-icon");
            const faqAnswer = faqQuestionDiv.nextElementSibling;
        
            faqAnswer.style.display = "none";
        
            const handleToggle = () => toggleFAQ(faqAnswer, plusIcon);
        
            plusIcon.addEventListener("click", handleToggle);
            plusIcon.addEventListener("keypress", (event) => {
                if (event.key === "Enter") handleToggle();
            });
        });
        
    2. Commenting for Other Developers 📝:

      • Add comments to explain your code for future maintainers. For instance:
        // Initialize FAQ answer to hidden state
        faqAnswer.style.display = "none";
        
        // Toggle FAQ visibility on click or Enter keypress
        
    3. Accessibility Considerations 🌟:

      • Ensure the plus-icon has proper tabindex for keyboard navigation and meaningful aria-label for screen readers.

    CSS Feedback 🎨

    1. Background Image Issue 🌐:

      • For the background image not spanning full width, try adding the background-size property like this:
        body {
            background-size: contain; /* Adjust based on your design preference */
        }
        
    2. Responsive Design 📱:

      • Test your design on various screen sizes to ensure the layout adapts well. You might need a media query for larger screens to fine-tune the layout.

    Summary 🌈

    Your code already looks promising! By making it more modular and developer-friendly with comments and accessibility improvements, it'll be even better! Let me know if you need further assistance. 😊

    Happy coding! 🚀

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

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub