Yet my Alert messagee isn’t displaying when I fill out all of those entries.
Here is the piece of code thats SUPPOSED to make that work:
if(setSuccessFor(username)&&setSuccessFor(email)&&setSuccessFor(password)&&setSuccessFor(confirmPassword)){
alert(“You filled out all input entries correctly”)
}
Well you can’t use it to check for any condition like you are now, it just does DOM manipulation. I would keep functions small and as specific to one task as possible (separation of concerns).
There are many ways you can do it.
Considering you already have all the logic inside the checkInputs function one option is to make the submit (or alert in this case) the default for the function. If you add a return after each call to setErrorFor it will validate each input separately, if it gets to the end of the function you call submit/alert. As all other conditions are handled before the end of the function the last thing to happen in the function will be the default (i.e. the submit/alert).
So whats wrong with this piece of code? if(usernameValue.classList.contains(“success”)&&emailValue.classList.contains(“success”)&&passwordValue.classList.contains(“success”)&&confirmpasswordValue.classList(“success”)){
alert(“GODD!”)
So I should have theoretically four returns in each block that contains the setErrorFor method? Would I be returning false? The alert message box should go at the end of my four if/else statements