Build a Leap Year Calculator - Build a Leap Year Calculator

Tell us what’s happening:

Hi, I can’t pass step 10 but result seems ok, could you help to check for me? Thanks.

Your code so far

const year = 0;
function isLeapYear(year){

if(year %4 === 0 && year %400 === 0){
return year + " is a leap year."} 

else if (year %4 === 0 && year %100 === 0){
  return year + " is not a leap year."
  } 
  
else if (year %4 === 0){
  return year + " is a leap year."
} 

else{
  return year + " is not a leap year.";
}


};
const result = isLeapYear(2000);

console.log(result);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0

Challenge Information:

Build a Leap Year Calculator - Build a Leap Year Calculator

Hi @timduncan0322

8. You should call the isLeapYear function and pass year as a parameter.

Are you sure you passed test 8?

Happy coding

yes, just miss step 10

Where you do define the year parameter? Which line of code?

I declare “year” in the 1st line (const year = 0;), and define it in the if statements, I not not sure if it is correct.

On which lines do you access that variable?

i think through the return lines, I also tried with the following, but still the same.

if(year %4 === 0 && year %400 === 0){

year = year + " is a leap year."

return year;

} else if (year %4 === 0 && year %100 === 0){

year = year + " is not a leap year."

return year;

} else if (year %4 === 0){

year = year + " is a leap year."

return year;

} else{

year = year + " is not a leap year.";

return year;

}

if Doesn’t define a variable.

You define year twice:

const year = 0;
function isLeapYear(year){

The first line, as you mentioned, and as a function parameter.

Can you think of how this affects scope?

got it, shouldn’t declare in the beginning, should be for testing only, thanks.

This is sufficient for testing. You should pretty much never define a variable that’s used as a parameter outside of the function.

yeah, but the tests want a year variable defined in the global scope

1 Like

In that case the function should be called with the variable and the parameter should have a different name, right?

you can open an issue on github for this if you want

but a global variable with a name, and a function parameter with the same name, while confusing, don’t interact with each other

1 Like

Wow, ok I really misunderstood that, thanks. It was really just the argument that was the problem.