Design comparison
SolutionDesign
Solution retrospective
Hello my name is João Vitor and i have completed another frontend mentor challenge.🔗
How can i improve and reduce unnecessary code? Leave your comment. 🙂
Community feedback
- @fazzaamiarsoPosted over 1 year ago
Hi Joao! Nice solution!
I have a tip to reduce your code. You can extract some logic into a smaller function.
function showError(elementId) { document.getElementsByClassName(`error-${elementId}`)[0].style.display = 'block'; document.getElementById(elementId).style.borderColor = 'hsl(354, 100%, 66%)'; } function hideError(elementId) { document.getElementsByClassName(`error-${elementId}`)[0].style.display = 'none'; document.getElementById(elementId).style.borderColor = 'hsl(120, 100%, 31%)'; } function checkFirstName() { const firstNameValue = firstName.value; if (firstNameValue === '') showError('firstName'); else hideError('firstName'); }
I hope it answers your question! Cheers!
Marked as helpful0@jvssvjPosted over 1 year ago@fazzaamiarso No doubt cleared my doubts, thank you friend. I just started in JS, my code is a mess but it works (sometimes) 😆
0
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