Repository navigation
Conversation
RHSebregts
left a comment
There was a problem hiding this comment.
Hi!
Thank you for this first task. There's a small issue regarding 0 and its leap year status. And a small grammar nitpick.
Also, even though small PR's are always recommended, putting every task in a separate PR might be slightly overdoing it. But at least you got some practice in making PR's and using git, so maybe it's a good thing?
| } else if (year <=1 || year >= 9999) { | ||
| console.log(`${year} Invalid year!`) | ||
| } else { | ||
| console.log(`${year} is not the leap year!`); |
|
|
||
| let year = Number(prompt('Enter the year: ')); | ||
|
|
||
| function CheckLeapYear(year) { |
There was a problem hiding this comment.
Really like this standalone function, which we can then use for the checks. That's a great pattern.
| if (year % 400 === 0) { | ||
| return true; | ||
| } else if (year % 100 === 0) { | ||
| return false; | ||
| } else if (year % 4 === 0) { | ||
| return true; | ||
| } else { | ||
| return false | ||
| } |
There was a problem hiding this comment.
Since you are using return you can use my all time favourite pattern for readable code: the early escape. That way we can get rid of all the else if statements. That's not a requirement, but a very nice pattern to use whenever you can to make your code nice and easy to read.
| } | ||
|
|
||
| if (CheckLeapYear(year)) { | ||
| console.log(`${year} is a leap year!`); |
There was a problem hiding this comment.
So, what about 0? Is that a leap year?
No description provided.