TheOdinProject/javascript-exercises

README.md hint doesn't match solution.js

Closed this issue · 3 comments

In Exercise 06 - leapYears, the README file has a hint that says "use an if statement and && to make sure all the conditions are met properly". However, the solution.js file doesn't even use an if statement, which can lead to confusion.

Thanks @jveneziano25.
Agreed that the current solution will be better replaced with something that's more intuitive and recognisable for most people at this point in the curriculum, i.e. using conditionals rather than returning a single complex boolean expression.

The solution I'd propose is:

const leapYears = function (year) {
  const isYearDivisibleByFour = year % 4 === 0;
  const isCentury = year % 100 === 0;
  const isYearDivisibleByFourHundred = year % 400 === 0;

  if (
    isYearDivisibleByFour &&
    (!isCentury || isYearDivisibleByFourHundred)
  ) {
    return true;
  } else {
    return false;
  }
};

module.exports = leapYears;

Let me know if you're happy to open a pull request with this change to the exercise's solution file or not, then I can assign you or open this up for assignment.

Go for it