Home > DeveloperSection > Forums > Check if year is leap year in javascript
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    May-03-2013 1:23 AM

 JavaScript JavaScript 
Ratings:


 1 Reply(s)
 1102  View(s)
Rate this:
Hi Everyone!

function leapYear(year){
    var result; 
    year = parseInt(document.getElementById("isYear").value);
    if (years/400){
      result = true
    }
    else if(years/100){
      result = false
    }
    else if(years/4){
      result= true
    }
    else{
      result= false
    }
    return result
 }
This is what I have so far (the entry is on a from thus stored in "isYear"), I basically followed this here, so using what I already have, how can I check if the 

entry is a leap year based on these conditions(note I may have done it wrong when implementing the pseudocode, please correct me if I have) Edit: Note this needs to 

use an integer not a date function

Please help me!
Thanks in advance!


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-03-2013 9:08 AM

Hi Ankit!

Try as following

function leapYear(year)
{
  return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}

Don't want to miss updates? Please click the below button!

Follow MindStick