<button onclick="isleap(1992)">Try it</button>
function isleap(year);
{
var yr=document.getElementById("year").value;
if ((parseInt(yr)%4) == 0)
{
if (parseInt(yr)%100 == 0)
{
if (parseInt(yr)%400 != 0)
{
alert("Not Leap");
return "false";
}
if (parseInt(yr)%400 == 0)
{
alert("Leap");
return "true";
}
}
if (parseInt(yr)%100 != 0)
{
alert("Leap");
return "true";
}
}
if ((parseInt(yr)%4) != 0)
{
alert("Not Leap");
return "false";
}
}
Having problems figuring out how to get the code to popup the alert box with the answer to the leap year.
A simple
isLeapYearfunction is:It just sees if 29 February occurs in the given year. You should be able to do:
on the basis that parsing an invalid date should return NaN, which type-converts to false, but not all browsers correctly implement
Date.parse. e.g.