Design comparison
Solution retrospective
Javascript is a lot harder than I expected. Any help is welcomed on how to improve, please help I don't know what I'm doing. I spent an hour trying to figure out why the Javascript wasn't working, only to realize I had my Javascript file as a link instead of a script in the HTML. My forehead is really, really, red right now.
Community feedback
- @3eze3Posted 9 months ago
Hey!🎃 Benji, good solution for this challenge.
First of all, these situations are normal in any learning environment. ✨
Some recommendations I could give you in JS:
-
Repetition of selections: In your code you select the inputs, this results in an unnecessary search every time the form is submitted, you could select the inputs outside the event.
-
Cascading classes: You are adding and removing the error class directly to the parent elements (input.parentElement), it works but it would be better if you use it directly in the input.
-
Redundant Mail Validation: You don't need to add and remove the error class twice for mail validation, you can remove the second case from the if handling.
I can think of something like this, more or less: const isValid = isEmailInput ? validateEmail(input.value) : input.value.trim() !== ""; if (!isValid) { input.classList.add("error"); } else { input.classList.remove("error"); }
- And the most important, create projects no matter if they are simple, or if it is to review a topic, just create using JS or another language you want to learn.♟
If you have any questions, feel free to contact me. 🎨🥼
Happy coding.🎞
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