Code Lab

Modo entrevista. Temporizador de 5 min, sin pistas y sin autocompletado

Leap year

FácilBasics5 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'.

Ejemplos

isLeapYear(2024)

Devuelve true

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

Devuelve false

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

Devuelve true

2000 divides by 400.

Preguntada en Infosys · Fuente

Cargando el editor…
  1. EntradaisLeapYear(2024)
    Esperadotrue
  2. EntradaisLeapYear(2023)
    Esperadofalse
  3. EntradaisLeapYear(1900)
    Esperadofalse
  4. EntradaisLeapYear(2000)
    Esperadotrue

Las pruebas ocultas se ejecutan al enviar