
Solution retrospective
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.
Please log in to post a comment
Log in with GitHubCommunity feedback
- @skyv26
Hello @CoolNight99,
Great work on the implementation! 👏 Here are some suggestions to improve your code and styling:
JavaScript Code Feedback 💡
-
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
andkeypress
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(); }); });
-
-
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
- Add comments to explain your code for future maintainers. For instance:
-
Accessibility Considerations 🌟:
- Ensure the
plus-icon
has propertabindex
for keyboard navigation and meaningfularia-label
for screen readers.
- Ensure the
CSS Feedback 🎨
-
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 */ }
- For the background image not spanning full width, try adding the
-
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.
- Test your design on various screen sizes to ensure the layout adapts well. You might need a
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