In this program, we will see how we can find a leap year. The condition for the leap year is
- The year must be divisible by 400 or
- The year must be divisible by 4 or not divisible by 100
Let’s write the code
year = prompt("Enter a year: ");
if((year % 4 == 0) & ( year % 100 != 0) || ( year % 400 == 0))
{
console.log("Leap year")
}
else
{
console.log("Not a leap year")
}
The output of the code is
Enter a year: 2000
Leap year
Enter a year: 2001
Not a leap year