function leapYear(year){ var result; year = parseInt(document.getElementById("isYear").value); if (years/400){ result = true } else if(years/100){ result = false } else if(years/4){ result= true } else{ result= false } return result }
This is what I have so far (the entry is on a from thus stored in "isYear"), I basically followed this here, so using what I already have, how can I check if the entry is a leap year based on these conditions(note I may have done it wrong when implementing the pseudocode, please correct me if I have) Edit: Note this needs to use an integer not a date function
Check if the number is evenly divisible by 400 to confirm a leap year. If a year is divisible by 100, but not 400, then it is not a leap year. If a year is divisible by both 100 and 400, then it is a leap year. For example, 1900 is evenly divisible by 100, but not 400 since it gives you a result of 4.75.
If a year is a century year, meaning divisible by 100, then it needs to be divisible by 400 to be called as a leap year. If a year is not a century year, then it needs to be divisible by 4 to be called as a leap year.
If the year can be evenly divided by 100, it is NOT a leap year, unless; The year is also evenly divisible by 400. Then it is a leap year.
function leapYear(year) { return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0); }
The function checks if February has 29 days. If it does, then we have a leap year.
ES5
function isLeap(year) { return new Date(year, 1, 29).getDate() === 29; }
ES6
const isLeap = year => new Date(year, 1, 29).getDate() === 29;
Result
isLeap(1004) // true isLeap(1001) // false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With