Build a Leap Year Calculator - Build a Leap Year Calculator

Tell us what’s happening:

  1. You should store the result of calling the isLeapYear function in a variable named result - FAILS

why? I am aware of let/const issue but how can I use const in this case?

Your code so far

let result;
let year;

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

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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36

Challenge Information:

Build a Leap Year Calculator - Build a Leap Year Calculator

Welcome to the forum @PawelFierka

You are declaring the variable as undefined.
Try declaring it with an assignment.

Happy coding

Hi there and welcome to our community!

You’ve basically got it. Just don’t declare result or year at the top of your code.
Declare and assign them each in a single line after your function.

thanks a lot, it worked.

thanks, it worked. Any explanation why it didnt work before?

Technically, your code worked, but failed the FCC tests, as they were presumably looking for single-line variable declaration/assignments.

1 Like