Build a Leap Year Calculator - Build a Leap Year Calculator

Tell us what’s happening:

I have checked the code repeatedly and look up most of questions on the forum, but I see no problems inside the code especially the ternary operator. Isn’t just ’ (year % 4 || year % 400) == 0 ’ enough for this problem?

Your code so far

function isLeapYear(year) {
  if ((year % 4 || year % 400) == 0) {
    return (year + ' is a leap year.')
  } else {
    return (year + ' is not a leap year.')
  }
}

const year = 2024
const 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/143.0.0.0 Safari/537.36

Challenge Information:

Build a Leap Year Calculator - Build a Leap Year Calculator

It looks like your function takes 1 argument, right?

function isLeapYear(year) {
  if ((year % 4 == 0) & (year % 100 > 0)) {
    return (year + ' is a leap year.')
  } else if ((year % 4 & year % 400) == 0) {
    return (year + ' is a leap year.')
  } else if ((year % 4 == 0) & (year % 100 == 0)) {
    return (year + ' is not a leap year.')

  }

}

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

I rewrote the code, and here’s the latest update.

This is the checklist so far. I’m running out of idea.

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

Think how you need to call a function that uses parameters in the execution statement.

Have a look closely at this example and see what you have missed and what you need to add to yours.

  1. With 1900 as the value of the year variable, the result should be 1900 is not a leap year.

Did you test this?

1900 is a leap year.
} else if ((year % 4 & year % 400) == 0) {

I would test this logic independently. Does it work the way you think?

function isLeapYear(year) {
  if ((year % 4 == 0) & (year % 100 > 0)) {
    return (year + ' is a leap year.')
  } else 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.')
  }
}

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

I executed the latest code update but get stuck with the above checkpoint. What’s your thought on this?

What happened here?

Try to follow the User Stories and implement them. Don’t rely on the tests.

  1. You should call the isLeapYear function with year as the argument and assign the result to a variable named result.