Skip to content
Exercise · Operators and type conversion · lesson 12 of 14

Exercise: leap year

Write a function function isLeap(year) that returns true if the year is a leap year, and false otherwise. A year is a leap year when it is divisible by 4 but not by 100. The exception is years divisible by 400: they are leap years.

  • isLeap(2024) → true
  • isLeap(1900) → false
  • isLeap(2000) → true

Constraints: year is a whole number from 1 to 9999.

Do not add extra imports unless the task says so explicitly.

leap.js — javascript
javascript · 4 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way