A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Checking For Leap YearsThis tutorial will show you how to create a JavaScript function that checks whether a given year is a leap year (366 days) or not (365 days). |
On Saturday, March 11th 2006 at 10:05 AM By Lewis Cowles (View Profile) ![]() ![]() ![]() ![]() (Rated 3.9 with 14 votes) |
||
|
Contextual Ads
More JavaScript Resources
Advertisement
In this tutorial I aim to teach you how to check valid leap years in JavaScript. Basically I want you to be able to understand how to go through the application development cycle to create the most basic of applications so that you have the underpinnings to progress onto more complex projects. I do not state that this code is perfect but it does work. Once you have understood how the code works then you should understand how to improve it and make it run a lot faster.
This code defines the store if you will that our little JavaScript employee will be working at so that we can run some tests by your new employee. It defines a form within the body where it gives a said field an ID so that our JavaScript employee knows what to look at. It then tells the html form to call over the assistant once the form is completed. All done you may have noticed that I got the function to return a value. This is for further expansion where other functions would check if there was a leap year so that for instance you could check the amount of days in February. I hope this Tutorial has thought you something or you at least thought it was informative to those who may wish to know how to do something like this |
|||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||
|
|||
Current Commentscouldn't you just do year mod 4 (parseInt(yr)%4==0), because leap years must be a multiple of 4?
Unfortunately for xmutantduck, the definition of a leap year is a bit more complicated than most of us learned growing up.
Not all years divisible by 4 are leap years.
A year is a leap year, if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
Thus, the year 1900 (which is divisible by both 4 and 100) is NOT a leap year. The year 2000 (which is divisible by 4, 100, and 400) is a leap year.
You can thank Pope Gregory XIII and the non-integral number of days in a solar year for this somewhat complicated scheme.
That code seems overcomplicated why don't you just use something like this C code:
if(Year % 400 == 0) leapyear=true;
else if(Year % 100 == 0) leapyear=false;
else if(Year % 4 == 0) leapyear=true;
else leapyear=false;
if (((year % 4 == 0)
another way of doing this:
function isLeap(year){
return (year % 400 == 0) || ((year % 4 == 0)
here is a good article: http://faq.puthik.com/js/js_faq_leapY.html
hi how r u
u r write
You can do simply by this function
function isLeapYear(yr) {
return new Date(yr,2-1,29).getDate()==29;
}
function isLeap(year) {
return (year % 400 == 0 || (year % 100 != 0
year % 4 == 0));
}
Your crappy comment engine cut the second line off.
function isLeap(year) {
return (year % 400 == 0 || (year % 100 != 0
Related Tutorials
Related Source Code
JavaScript Job Search