Build a Leap Year Calculator - Build a Leap Year Calculator

Tell us what’s happening:

Hello everyone ! I have a problem with solving this task. My code seems to be working for 2024 leap year, but not for 1900, and I really don’t understand why. I searched for typos and didn’t find anything. Please help !

Your code so far


function isLeapYear(year) {
// years that are leap year
if(year % 4 === 0 || year % 4 === 0 && year % 100 === 0 && year % 400 === 0){
  return `${year} is a leap year.`;
} 

// years that are not leap year
else if (year % 4 === 0 && year % 100 === 0){
  return `${year} is not a leap year.`;
} else {
  return `${year} is not a leap year.`;
}
}

let year = 1900;

let result = isLeapYear(year);
console.log(result); //logs "1900 is leap year"




Your browser information:

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

Challenge Information:

Build a Leap Year Calculator - Build a Leap Year Calculator

Welcome to the forum @coding_is_fun

With a few changes, I can make your code pass.

Start by looking at the if condition.

If it helps, write it out in a sentence.

Happy coding

I also have the same issue: 2024 and 2000 both print the “yes leap year” statement, but 1900 does not print “1900 is not a leap year.” Maybe we have the logic wrong.

Below is my code as well:

const year = 1900;

function isLeapYear(year) {

if (year % 4 === 0) {

 return \`${year} is a leap year.\`;

}

else if (year % 100 === 0 && year % 400 !== 0 ) {

return \`${year} is not a leap year.\`;

}

else {

return "Try a different year.";

}

}

const result = isLeapYear(year);

console.log(result);

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.