DOM&AJAX homework solution#2
DOM&AJAX homework solution#2DwinaTech wants to merge 6 commits intoCodeYourFuture:masterfrom DwinaTech:master
Conversation
IsmaelMartinez
left a comment
There was a problem hiding this comment.
Good job.
When functions get a bit big, that tend to indicate that is better to split them into smaller ones.
Try to split them into small reusable pieces of code.
js/homework.js
Outdated
| pram.preventDefault() | ||
| if(nameValid.value !== '' && textAreaValid.value !== '' && emailValid.value.includes('@')){ | ||
| alert('Thank you for filling out the form'); | ||
| }else if (nameValid.value === '' || textAreaValid.value === '' || !emailValid.value.includes('@')){ |
There was a problem hiding this comment.
It will be better to add it into small separate functions for each case. So, isValidName will return true/false and set the backgroundColor depending on that.... and same for all the other elements.
If you really want, you can create 2 functions.
`function setBackgroundColor(element, color) {
element.style.backgroundColor = color;
}
function validateIsEmpty(element) {
return element.length === 0;
}
function validateName(){
if (validateIsEmpty(nameValid)){
setBackgroundColor(nameValid, 'red');
}
}
`
... same for email.
…o created elementColor function instade of add to every element styyling
I created functions for three different buttons and form validation.