@itush
Posted
Congratulations on completing the challenge! π
-
As per your code the date the validation will pass even though the date is invalid.
-
To fix the issue, we should check the maximum number of days for the given month and then checks if
inputDate.days
is greater than this maximum value. -
Modify your checkInputs function as follows and it should work even with leap years.
const daysInMonth = (month, year) => {
// Use a Date object to get the last day of the given month
return new Date(year, month, 0).getDate();
};
if(inputDate.days > daysInMonth(inputDate.months, inputDate.years)){
errorDays.innerHTML = "Must be a valid day";
valid = false;
}
-
I remember when I started out, I made countless mistakes and spent long hours searching for solutions. But hey, you don't need to go through the same struggles! π To help you shorten the learning curve, I recommend going through the following articles. They contain valuable insights that can make your journey smoother:
ππ 12 important CSS topics where I discuss about css position, z-index, box-model, flexbox, grid, media queries, mobile-first workflow, best practices etc. in a simple way.
ππ 11 important HTML topics
I hope you find these resources helpful in your coding adventures! π€
I'm eagerly looking forward to seeing the amazing projects you'll create in the future! ππ»
Keep up the fantastic work and happy hacking! πͺβ¨
Marked as helpful
@RobertoMada
Posted
@itush thank you very much for taking time to provide a solution to my problem and for the articles. I changed my code how you suggested and it works just fine π.
@itush
Posted
@RobertoMada You are most welcome!
I'm glad to hear that the solution worked.
Always happy to help ;)
@itush
Posted
@RobertoMada
I hope you're doing well and building cool stuffs ππ»
Today I was wondering, if you could spare a moment to give my GitHub pinned projects a βοΈ star.
It would mean the world to me, and help me provide quality support to the communityπ