Build a Leap Year Calculator - Build a Leap Year Calculator

Tell us what’s happening:

Hello,

If you look at my code the following part returns undefined for some reason, I can’t figure it out year%400 ==0

Your code so far

const year = 1984

function isLeapYear(year) {
  if(year%4 == 0 && year%400 ==0){
    return `${year} is a leap year`
  }

}

const result = isLeapYear(year)
console.log(isLeapYear())

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36

Challenge Information:

Build a Leap Year Calculator - Build a Leap Year Calculator

Your if statement will execute if both of he conditions are true. Are they?

console.log(year%4 == 0)
console.log(year%400 == 0)

If they aren’t true, there’s nothing else to return so the function returns undefined

when you are calling the function like this the parameter year gets the value of undefined

1 Like

Thanks, why isn’t console.log(year%400 == 0) true also?

what value would undefined % 400 give?

Try this instead:

function isLeapYear(year) {
    console.log(year)

I think you need to fix this: