Programming with JavaScript

⌘K
  1. Home
  2. Docs
  3. Programming with JavaScri...
  4. Practice Programs
  5. Find given year is a leap year in the Gregorian Calendar

Find given year is a leap year in the Gregorian Calendar

Example: 1B

Write a JavaScript to determine whether a given year is a leap year in the Gregorian calendar.

Script

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: 11

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments