Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Conversation

@DwinaTech
Copy link

I created functions for three different buttons and form validation.

@DwinaTech DwinaTech closed this Jun 18, 2017
@DwinaTech DwinaTech reopened this Jun 18, 2017
Copy link

@IsmaelMartinez IsmaelMartinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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('@')){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants