Leap Year
Programming Basics · JavaScript
TASK
Problem
Given `year`, print `YES` if it is leap: divisible by 400, or divisible by 4 but not by 100.
EXAMPLE
Example
2024
YES
LIMITS
Constraints
`year` is a positive integer representing a Gregorian calendar year.
LEARN
Theory for this problem
+
### Leap Year
`if / else if / else` chooses a branch from boolean conditions. Comparisons such as `<`, `>=`, `===` and logical operators `&&`, `||`, `!` combine the exact rules that decide which output is valid.
NEED HELP?
Hints
+
['Translate every case from the statement into a boolean condition before writing branches.', 'Order the checks so a more specific case is not swallowed by a broader condition.']
ANSWER
Solution
+
const fs = require('fs');
const year = Number(fs.readFileSync(0, 'utf8').trim());
const leap =
year % 400 === 0 ||
(year % 4 === 0 && year % 100 !== 0);
console.log(leap ? 'YES' : 'NO');