Programming with JavaScript

⌘K
  1. Home
  2. Docs
  3. Programming with JavaScri...
  4. Example Programs
  5. Year is leap or not

Year is leap or not

Example 12:

Write a JavaScript to check whether a year is leap or not

const prompt = require("prompt-sync")();

let year = prompt("Enter year");

year = parseInt(year);

if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
  console.log(`${year} is leap year`);
} else {
  console.log(`${year} is not leap year`);
}

Output:

Loading

Views: 113

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments