Leap year
Easy
23
60.6% Acceptance
Write a function isLeapYear(year)
that takes in an integer number year
as the argument and returns true
if year
is a leap year, and false
otherwise.
A leap year is:
- divisible by 400
- divisible by 4, but not by 100
Instructions
- Should return
false
ifyear
is less than or equal to 0. - Should return
true
ifyear
is a leap year. - Should return
false
ifyear
is not a leap year.
Example test cases
isLeapYear(2000) => true // divisible by 400 isLeapYear(2001) => false // not divisible by 4 or 400 isLeapYear(2004) => true // divisible by 4, but not by 100 isLeapYear(2100) => false // divisible by 4 and 100
Hints
- You can use multiple if statements to return early when certain criteria are met.