Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6863855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:50:18+00:00 2026-05-27T02:50:18+00:00

I do not usually use JavaScript, and cannot see why this is not working.

  • 0

I do not usually use JavaScript, and cannot see why this is not working. Thanks.

function testYear() {
    var dObject = new Date();
    var dRegEx = /^[0-9][0-9]00$/;
    var d = dObject.getFullYear();

    if (d.match(dRegEx) && d % 400 == 0) {
    alert("The year "+d+" is in fact a leap year!");
    //return true;
    }
    else if(!(d.match(dRegEx) && d % 400) && d % 4 == 0) {
    alert("The year "+d+" is in fact a leap year!");
    //return true;
    }
    else {
    alert("The year "+d+" is not a leap year.");
    //return false;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:50:19+00:00Added an answer on May 27, 2026 at 2:50 am

    There’s no need to use a regular expression here. Just use an ordinary integer arithmetic to see if the year is divisible by 100:

    if (d % 100 === 0 && ...)
    

    By the way, if d % 400 === 0 then it is automatically true that d % 100 === 0 so the extra test is unnecessary.


    A year is a leap year in the Gregorian calendar either if it is divisible by 400 or if it is divisible by 4, but not by 100. Try this instead:

    if ((d % 400 === 0) || (d % 4 === 0 && d % 100 !== 0))
    {
        // is leap year
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I usually do not have difficulty to read JavaScript code but for this one
I usually do not use Sql Server Management Studio, I usually use Linqpad to
when releasing an instance that could exist or not, I usually write this: if
As I use the web, I regularly get runtime errors (usually javascript) being reported
When I am writing Javascript, I use window.alert() to debug. Usually I pass variables
I assume this would be an issue with any JavaScript framework. I use MooTools
I have read in a lot of places that assembly language is not usually
I usually try to do TDD with not much analysis (no diagrams) before start
Usually it will ignore C files that are not documented, but I'd like to
They usually involve generics. But some methods with generics don't have them, and not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.