Javascript program to check leap year.

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

Facebook
Twitter
LinkedIn
Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

ABOUT ME !!
Johan William

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

RECENT POSTS

TEST