This question already has an answer here:
- javascript to find leap year 7 answers
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
The function checks if February has 29 days. If it does, then we have a leap year.
ES6
If you're doing this in an Node.js app, you can use the leap-year package:
Then from your app, use the following code to verify whether the provided year or date object is a leap year:
Using a library like this has the advantage that you don't have to deal with the dirty details of getting all of the special cases right, since the library takes care of that.
A faster solution is provided by Kevin P. Rice here:https://stackoverflow.com/a/11595914/5535820 So here's the code:
You can try using JavaScript's Date Object
This will return true or false.
My Code Is Very Easy To Understand