Design comparison
Solution retrospective
Would like feedback on whether the javascript written was good code or couldve been written better.
Community feedback
- @tomthestromPosted over 3 years ago
Hey Eric, it's easy to read, I see what it means to do, good job on that. Since you asked for feedback, I have a few things to say.
Did you test it? You're using a
validEmail()
function that is not defined.Everything is in global namespace, which for this app with a few lines is alright, but you could solve it with an
IIFE
.isvalidateEmail
is not camelCase and sounds like it does 2 things, while it only does one. I would call itisValidEmail
since it returnstrue
orfalse
based on a regex.You could extract the part where you do:
email.classList.add('error'); email.innerText = 'Email cannot be blank'; email.classList.add('error'); email.innerText = 'Email is invalid!';
into a function. You could have a place to store these error messages, and then just pass the error message to
email.innerText
based on the given parameter.const small = form.querySelector('small');
this way of selecting an element is error prone, you should either use anid
or adata
attribute. You need to be able to always uniquely identify the element you wanna manipulate. Imagine you'd have another<small>
element in the form, this code could break.Also for the github repo, you should not be having a directory and nothing else at the root level. You should move the contents of that directory into root. While at it, I would include a
.gitignore
and aREADME.md
file.Have a good day,
Tom
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