@demi05Submitted about 1 year ago
I could not figure out a way to handle the logic for days in February. Any advice?
I could not figure out a way to handle the logic for days in February. Any advice?
I made an array to hold known leap years starting from 1952 up until 2020. If the value of the year input was included in the leapYears array, the month value was 2, and the day value was greater than 29, then the entire date would be flagged as invalid.
If the 'years' value was not included in 'leapYears', the 'month' value was 2, and the 'day' value was greater than 28, then the entire date would be flagged as invalid as well.
const leapYears = [1952, 1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020];
let isDateValid = false;
let day = userInputDay;
let month = userInputMonth;
let year = userInputYear;
if(leapYears.includes(parseInt(year)) && parseInt(month) === 2 && parseInt(day) > 29 {
isDateValid = false;
} else if(!leapYears.includes(parseInt(year)) && parseInt(month) === 2 && parseInt(day) > 28 {
isDateValid = false;
}
//"isDateValid = false" = show date error
Let me know if this helped you in any way. Great work with your solution!