Code Lab

Leap year

EasyBasics5 min

Write a function isLeapYear(year) that returns true if the year is a leap year and false if it is not.

  • The parameter year is an integer from 1 to 9999.
  • A year is a leap year if it divides by 4 with no remainder: 2024 is a leap year, 2023 is not.
  • Exception: a year that divides by 100 is a leap year only if it also divides by 400. 1900 is not a leap year, 2000 is.
  • Return a boolean: true or false, not the string 'true'.

Examples

isLeapYear(2024)

Returns true

2024 divides by 4 and does not divide by 100.
isLeapYear(1900)

Returns false

1900 divides by 100, but not by 400.
isLeapYear(2000)

Returns true

2000 divides by 400.

Asked at Infosys · Source

Loading the editor...
  1. InputisLeapYear(2024)
    Expectedtrue
  2. InputisLeapYear(2023)
    Expectedfalse
  3. InputisLeapYear(1900)
    Expectedfalse
  4. InputisLeapYear(2000)
    Expectedtrue

Hidden tests run on Submit.