-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleapYear.js
37 lines (32 loc) · 826 Bytes
/
leapYear.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
// Simple Logic
// Year will be a leap year if the year is divisible by 4
function isLeapYear(year) {
if (year % 4 === 0) {
return true;
} else {
return false;
}
}
const leapYear = isLeapYear(2043);
console.log(leapYear);
*/
/**
1. Those year that is not divisible by 100 and if the year is divisible by 4 then it will be a leap year
2. If the year is divisible by 400, then it is a leap year
3. Else it is not a leap year
*/
function isLeapYear(year) {
if (year % 100 !== 0 && year % 4 === 0) {
return true;
} else if (year % 400 === 0) {
return true;
} else {
return false;
}
}
const leapYear = isLeapYear(2100);
const leapYear2 = isLeapYear(2400);
const leapYear3 = isLeapYear(1900);
const leapYear4 = isLeapYear(2052);
console.log(leapYear, leapYear2, leapYear3, leapYear4);