Leap Year Calculator Lab

In the Leap Year Calculator Lab I’m not passing the following tests, and I’m not sure why:

  • Failed:5. With 2024 as the value of the year variable, the result should be 2024 is a leap year..

  • Failed:6. With 2000 as the value of the year variable, the result should be 2000 is a leap year..

  • Failed:7. With 1900 as the value of the year variable, the result should be 1900 is not a leap year..

My code:

let year = 2000;


function isLeapYear(number) {
    return 0 === number % 4 && 0 === number % 100 && 0 === number % 400 ? year + ' is a leap year.'
    : 0 === number % 4 && 0 === number % 100 ? year + ' is not a leap year.'
    : 0 === number % 4 ? year + ' is a leap year.'
    : year + ' is not a leap year.';
}

let result = isLeapYear(year);

console.log(result);

Thanks, please let me know what I might not be thinking about correctly in my code.

what is the value of number, what is the value of year? can you use both interchangeably?

1 Like

I see, I fixed that and pass that tests. However, I am still a bit confused - Is it true that, yes, you can use them interchangeably, at least in the context of number as a parameter or placeholder for a value to be used by the function isLeapYear()?

Is it necessary that they are the same variable or under what contexts does it matter/not matter?

no, you can’t use them interchangeably:

let year = 2000;


function isLeapYear(number) {
    return 0 === number % 4 && 0 === number % 100 && 0 === number % 400 ? year + ' is a leap year.'
    : 0 === number % 4 && 0 === number % 100 ? year + ' is not a leap year.'
    : 0 === number % 4 ? year + ' is a leap year.'
    : year + ' is not a leap year.';
}

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

console.log(isLeapYear(2001));
console.log(isLeapYear(2002));
console.log(isLeapYear(2003));

if you have multiple function calls like this, the value of the global variable is the same, but the number parameter has different values

if you want your function to be reusable, use the parameter

1 Like

Thanks, that makes tons of sense!