DEV Community

Discussion on: Creating a JavaScript Function to Calculate Whether It's a Leap Year

nas5w profile image
Nick Scialli (he/him) Author • Edited

What I'm saying is that your function literally doesn't work correctly.

isLeapYear(2100);
// true

That's incorrect.

Thread Thread
lucs1590 profile image
Lucas de Brito

Oh, sorry, you're right! I forget something.
Try again with my changes.

Thread Thread
nas5w profile image
Nick Scialli (he/him) Author

In this case, why do you even need the ternary? true will always evaluate to true.

In other words, this:

true ? ((year % 400 === 0) || (year % 100 !== 0)) && ((year % 4) == 0) : false;

is the exact same thing as this:

((year % 400 === 0) || (year % 100 !== 0)) && ((year % 4) == 0);
Thread Thread
lucs1590 profile image
Lucas de Brito

Perfect!!
I totally agree with you! 👏👏👏👏👏👏