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

pablodev | FAQ accordion

P
pablodev• 430

@Pabloodev

Desktop design screenshot for the FAQ accordion coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


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

As I'm still very new to JavaScript, everything has been very difficult so far, I don't know what it would be like without the chat, or other people's solutions, because even the documentation is difficult to understand, but I know that everything is constant and that all this It's going to get into my head at some point

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

*the whole JavaScript issue

I always put it on chatGPT and asked him to explain it to me line by line and why, I always try to use AI to teach me and not do it for me*

What specific areas of your project would you like help with?

If anyone had feedback on my code or even a tip on how to better learn JavaScript, I would be very grateful!

Community feedback

Mahmood• 1,070

@MahmoodHashem

Posted

Hello,

Congratulations on successfully completing your challenge.

Your project is impressive, with clean and cool code.

I have some suggestions to further improve it:

  • The FAQ section should behave like an accordion, where opening one question hides the others. You can achieve this by querying all the paragraphs and using conditional logic in a foreach loop to hide or show them.

Here is the updated version of your code, where the answer paragraphs have a class added to hide them:

document.addEventListener("DOMContentLoaded", function() {
    const buttons = document.querySelectorAll(".toggle-button");
    const paragraphs = document.querySelectorAll(".question-answer");

    buttons.forEach((button, index) => {
        button.addEventListener("click", function() {
            paragraphs.forEach((p, i) => {
                if (i === index) {
                    p.classList.toggle('hide');
                    button.src = p.classList.contains('hide')
                        ? './assets/images/icon-plus.svg'
                        : './assets/images/icon-minus.svg';
                } else {
                    p.classList.add('hide');
                    buttons[i].src = './assets/images/icon-plus.svg';
                }
            });
        });
    });
});

Keep up the hard work

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