@Gielth
Posted
Hi man, nice code, just a few notes to help you out making it better...
In your js file on line 75, where you used "if (Boolean(day) === false) { document.getElementById("req1").innerHTML = "This field is required"; regday.classList.add("required"); dayInput.classList.add("required"); }"
you can continue this line of code, with what you used on line 93
"if (day > maxDay) { document.getElementById("req1").innerHTML = "Must be a valid day"; dayInput.classList.add("required"); regday.classList.add("required"); day = false; }"
by joining then with if { } else if { } like this:
"if (Boolean(day) === false) { document.getElementById("req1").innerHTML = "This field is required"; regday.classList.add("required"); dayInput.classList.add("required"); } else if (day > maxDay) { document.getElementById("req1").innerHTML = "Must be a valid day"; dayInput.classList.add("required"); regday.classList.add("required"); day = false; }"
This way, your code does have and incredible amount of if's that need to be checked, cause the subsequentials "if" only run in the case of the previous argument check being false...
To further improve it you could make this check in a function that uses the variable you're looking, such as day or month, and maxDay and maxMonth...
I recomend that you study a bit on functions, functions uses and functions properties such as the use of "return value" this way you can eliminate some codes like the btn.removeEventListener... that i don't believe it's needed in this...
Here you can read a bit for the functions and their uses:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions
hope this help you out in your coding...
Marked as helpful
@Feng-09
Posted
@Gielth thanks a lot. I didn't even think about that else if, but I understand. I'll read more on functions too, thanks