
Design comparison
SolutionDesign
Community feedback
- @skyv26Posted 3 months ago
Hi @drishti1920, 👋
Your project looks great and functions well! However, here are some suggestions to make it even better:
💡 JavaScript Code Improvements
-
Compact and Readable Code:
- Refactor the code to follow the DRY (Don’t Repeat Yourself) principle.
- Modularize the repetitive parts like resetting and adding the active class to make the logic reusable and clean.
- Here's an example of a more compact approach:
const toggleActiveClass = (points, selectedPoint) => { points.forEach((p) => p.classList.remove("active")); selectedPoint.classList.add("active"); }; ratingPoints.forEach((point) => { point.addEventListener("click", () => { toggleActiveClass(ratingPoints, point); selectedRating = point.dataset.value; }); }); submitButton.addEventListener("click", () => { if (selectedRating) { selectedScore.textContent = `You selected ${selectedRating} out of 5`; ratingContainer.style.display = "none"; thankyouContainer.style.display = "block"; } else { alert("Please select a rating before submitting!"); } });
-
Code Semantics: Use meaningful names for variables and methods to improve code readability. For example,
toggleActiveClass
clearly explains its purpose.
🛠️ HTML and CSS Enhancements
- Remove Redundant Comments: Cleaning up unnecessary comments improves maintainability and avoids confusion. Keep only relevant comments that add value to understanding the code.
- Follow Semantic HTML: Ensure that your structure adheres to semantic principles. For instance:
- Use
<button>
instead of<div>
for clickable elements. - Add proper ARIA attributes for accessibility.
- Use
🌟 Additional Suggestions
- Add transition effects for rating selection to improve user experience.
- Consider validating the form input dynamically instead of relying on an alert.
Marked as helpful0 -
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