@tomthestrom
Posted
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 it isValidEmail
since it returns true
or false
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 an id
or a data
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 a README.md
file.
Have a good day,
Tom