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

DOM&AJAX homework solution#2

Open
DwinaTech wants to merge 6 commits into
CodeYourFuture:masterfrom
DwinaTech:master
Open

DOM&AJAX homework solution#2
DwinaTech wants to merge 6 commits into
CodeYourFuture:masterfrom
DwinaTech:master

Conversation

@DwinaTech

Copy link
Copy Markdown

I created functions for three different buttons and form validation.

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

@IsmaelMartinez IsmaelMartinez left a comment

Copy link
Copy Markdown

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.

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

Copy link
Copy Markdown

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