Code Lab

Modo entrevista. Cronômetro de 5 min, sem dicas e sem autocompletar

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'.

Exemplos

isLeapYear(2024)

Retorna true

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

Retorna false

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

Retorna true

2000 divides by 400.

Cobrada em Infosys · Fonte

Carregando o editor...
  1. EntradaisLeapYear(2024)
    Esperadotrue
  2. EntradaisLeapYear(2023)
    Esperadofalse
  3. EntradaisLeapYear(1900)
    Esperadofalse
  4. EntradaisLeapYear(2000)
    Esperadotrue

Os testes ocultos rodam no envio