Build a Leap Year Calculator - Build a Leap Year Calculator

Tell us what’s happening:

My code seems to work as I can pass any year into it and get correct results in the console. However, it keeps failing tests 5, 6, 7 depending on which year I check last in my code.
For example, checking 2024 last lets me pass test 5, but 6 and 7 fail.
Checking 1990 last lets me pass test 7, but 5, 6 fail.

I feel like my code is functional, but I’m missing something specific FCC is expecting. Any ideas? Thanks!

Your code so far

function isLeapYear(num) {
  if (num % 4 === 0 && !(num % 100 === 0) ) {
    return `${year} is a leap year.`
  }
  else if (num % 400 === 0) {
    return `${year} is a leap year.`
  }
  else {
    return `${year} is not a leap year.`
  }
};

let year = 2024;
let 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/151.0.0.0 Safari/537.36

Challenge Information:

Build a Leap Year Calculator - Build a Leap Year Calculator

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-leap-year-calculator/66c06fad3475cd92421b9ac2.md at main · freeCodeCamp/freeCodeCamp · GitHub

Welcome to the forum @millennial_falcon,

Are you always using the num parameter inside the function?

Happy coding

Thanks for the welcome!
Changing my ${year} to ${num} did the trick. I see the way I had things “worked” because those variables happened to be the same value.
Is this bad practice because num could have it’s value changed within the function and therefore end up being a different value than year?
Thanks for the help

It’s bad practice to make a function dependent on a global variable. A well-crafted function only uses the parameters passed to it in a function call.