-
Notifications
You must be signed in to change notification settings - Fork 19
Yana P #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Yana P #5
Conversation
YanaP1312
commented
Jan 20, 2026
- Added a check for a leap year (task-1);
- Added logic for fn to login.js (task-2);
- Fixed converter & added feature (task-3).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @YanaP1312 ! Thanks for submitting the assignment! Nice job on this assignment! You completed all three tasks successfully, well done!
I’ve left a few small comments to keep in mind for future improvements. Let me know if anything is unclear.
| // Step 1: prompt the user to enter a year | ||
| // Step 2: convert the user input to a number so we can perform calculations | ||
| // Step 3: Implement the logic | ||
| if (year < 1 || year > 9999) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition validates the year range correctly.
However, if the user enters text instead of a number, Number() returns NaN, and this check doesn’t catch it. That’s why the program prints Yes, NaN is a leap year.
Could you think of a way to improve this check?
| // Step 3: Implement the logic | ||
| if (year < 1 || year > 9999) { | ||
| console.log("Invalid year!"); | ||
| } else if (!(year % 400) || (!(year % 4) && (year % 100))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job, this condition correctly covers all the leap year rules!
For readability, you could consider writing the logic in a more easier to read way.
Another possibility is assigning it to a variable like isLeapYear. This would make the code easier to read and avoid repeating logic in the future. This is an optional improvement to keep in mind.
const isLeapYear = (year % 4 === 0) && (year % 100 !== 0 || year % 400 === 0);
if (isLeapYear) {
console.log(`Yes, ${year} is a leap year`);
} else {
console.log(`No, ${year} is not a leap year`);
}
| if (incorrectAttempts > 3) { | ||
| errorMessage("Login blocked: Too many incorrect attempts"); | ||
| return; | ||
| } else if (isValid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that you used a boolean (isValid), this makes more readable 👍
| errorMessage("Login blocked: Too many incorrect attempts"); | ||
| return; | ||
| } else if (isValid) { | ||
| incorrectAttempts = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, resetting incorrectAttempts after a successful login is a good idea, but it wasn’t required in the task instructions. For the future, whenever you add extra things, check if the behavior is expected.