Build a Leap Year Calculator - Build a Leap Year Calculator

Tell us what’s happening:

I don’t get it with what is wrong with my code. I keeps saying " You should store the result of calling the isLeapYear function in a variable named result" . I did so but it won’t pass. I need someone to help me here! Thanks in advance

Your code so far

let year = 1900;
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  && year % 100!=0) {
    return `${year} is a leap year.`
  } else {
    return `${year} is not a leap year.`
  };
};
let result =isLeapYear();
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/131.0.0.0 Safari/537.36

Challenge Information:

Build a Leap Year Calculator - Build a Leap Year Calculator

Check your function call. The isLeapYear function takes a required parameter.

Thanks for your answer. In fact I have tried different things but none of them fulfills the mission. whatever I try it won’t validate:
let result = isLeapYear();
let result = isLeapYear(year);
let result = isLeapYEar(2024);
It keeps returning : “You should store the result of calling the isLeapYear function in a variable named result.”.
Any idea about what’s missing?

Seems like the test is expecting a const declaration for the result variable.


Edit: I made an issue for it.

2 Likes

share your latest code please

1 Like

Thanls for you answer. Here is my latest code that’s stuck on one step as I mentioned before. ( ps. the backticks may be not visible but they are correctly inserted in my code) Thanks for your help in advance.
let year = 2024;
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 && year % 100!=0) {
return ${year} is a leap year.
} else {
return ${year} is not a leap year.
};
};
let result = isLeapYear();
console.log(result);

I don’t see any changes to the original code you posted. Your variable declarations should be using const, not let, because their values do not change. (Future tests may allow let declarations thanks to the issue @lasjorg submitted.) And your function call should include the required parameter.

1 Like

When you call isLeapYear() you need to pass it the year argument.

1 Like

Thanks for your help. It finally worked :slight_smile:
Indeed, the only solution allowed was by using const for my variable declaration and including the required parameter.