var yr=prompt("Enter a year",""
The rule for leap years is it's a leap year if the year is both evenly divisible by 4 and not evenly divisible by 100. However, all years evenly divisible by 400 are also leap years. So, a simple function to tell you if it's a leap year or not could be done like this:
function isLeapYear(yr)
{
if (((yr%4==0) && (yr%100!=0)) || yr%400==0) {
return true;
} else {
return false;
}
}
You should also insert some sanity checks before passing the year to the function (make sure the user entered a value, and that the value is a positive number etc.).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.