Responsive tip calculator using html, css(scss) and javascript

Please log in to post a comment
Log in with GitHubCommunity feedback
- P@leeport511
Great Job! here are some advices for make your code more simple without redundancy.
Reduce Repetitive Selections
Instead of selecting each tip button individually, you can use
querySelectorAll
to grab all tip buttons at once and loop through them when needed. The same applies to error elements.Encapsulate Error Clearing
You can Create a
clearErrors()
function to remove all error messages and input outlines.Simplify Value Parsing
Used
Number(value) || 0
to handle empty inputs gracefully, reducing the need for conditional checks.Reuse Logic with forEach
When validating inputs, instead of handling them separately, you can loop through the values and their corresponding elements to apply errors dynamically.
Marked as helpful
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