Build a Leap Year Calculator - Build a Leap Year Calculator

Tell us what’s happening:

Hi
I have a issue with my code. Sometimes I get correct results for leap years or not leap years never both at the same time. It seems that it is depended on the year that attach to the year variable. Those console.log at the bottom are just for my testing and from what is see they are correct. I tried to pass the code without them and it still didn’t work. I would love some help. Thanks in advance :slight_smile:

Your code so far

function isLeapYear(a) {
  if (a%400 === 0 || (a%100 !== 0 && a%4 === 0)) {
    return year + " is a leap year.";
  } else {
    return year + " is not a leap year.";
  }
}
let year = 2026;
let result = isLeapYear(year);
console.log(result);

year = 2024;
result = isLeapYear(year);
console.log(result);

year = 2000;
result = isLeapYear(year);
console.log(result);

year = 1900;
result = isLeapYear(year);
console.log(result);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Leap Year Calculator - Build a Leap Year Calculator

you have a as function parameter, right?

so where does year come from?

thanks for opening my eyes. It works now.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.