473,672 Members | 2,589 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

find the leap year by using for loop

1 New Member
enter any year than display the leap or not
Jan 19 '15 #1
2 2419
Exequiel
288 Contributor
You don't need for loop to determine if leap year or not. Try this code I made.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Zick Sample</title>
  4. <script>
  5. function leapyear()
  6. {
  7.     var year = document.getElementById("inputyear").value;
  8.     if(year != "")
  9.     {
  10.         if ((year % 4 == 0) && year % 100 != 0)
  11.         {
  12.             alert(year + " is a leap year.");
  13.         }
  14.         else if (year % 400 == 0)
  15.         {
  16.             alert(year + " is a leap year.");
  17.         }
  18.         else
  19.         {
  20.             alert(year + " is not a leap year.");
  21.         }
  22.     }
  23. }
  24. </script>
  25. </head>
  26. <body>
  27. <form method="post" action="javascript:;">
  28.     <input type="text" id="inputyear" placeholder="Enter the year."><br>
  29.     <input type="submit" value="Submit" onclick="leapyear()">
  30. </form>
  31. </body>
  32. </html>
  33.  
Jan 20 '15 #2
Dormilich
8,658 Recognized Expert Moderator Expert
one of the best leap year calculations I found:
Expand|Select|Wrap|Line Numbers
  1. (new Date(year, 1, 29).getDate() === 29)
Jan 20 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
4755
by: Protoman | last post by:
Hi!!! I need some help on a project I'm that calculates leap years; I'm getting errors that I have no idea what they mean; here's the code: #include <iostream> #include <cstdlib> using namespace std; class Year { public:
8
2966
by: rn216_ccc | last post by:
Hi there all, I found a web site,. http://www.onlineconversion.com/leapyear.htm, where it can give a list of leap years by within the given range by the user, or the user may enter a year and the program will make the decision if it is a leap year or not. In addition, I kind of understand that there are certain rules to calculating leap years. For instance, if the year is divisable by 4 and if the year is not divisable by 100 but is...
3
3646
by: xGx | last post by:
Hi please could someone help. i have created this programming so you can work out if there is a LEAP YEAR. But i need it to handle centuries. heres the code def isLeapYear (year): result = year % 4 if result > 0: print "It is NOT a leap year" else: print "It IS a leap year"
7
3537
by: karafire2003 | last post by:
Hey there...i was wondering if someone can help me with my program. I'm doing the leap year program thing. i thought i had it all figured out, but it ALWAYS says that it's not a leap year. here's my code...if you can help i'd gladly appreciate it. int year, test4, test100, test400; printf("The amazing leap year teller thingie thing!!!\nPlease enter the year to be tested: "); scanf("year"); test4 = year%4; test100 = year%100;...
8
3907
by: SONIQ | last post by:
You can determine whether a year is a leap year by testing if it is divisible by 4. However, years that are also divisible by 100 are not leap years, unless they are also divisible by 400, in which case they are leap years. Write a script that allows a user to enter a year and then determine whether the year entered is a leap year. Include a form with a single text box where the user can enter a year. Display an alert dialog box to the user...
12
7680
by: Brigitte Behrmann | last post by:
Can anyone assist with my code. I just cannot get this to work: I have to write a script that allows the user to enter a year & then determine whether it is a leap year or not. The request is for a form with a single text box and using an alert dialog box stating if the entered year is a standard or leap year. Code so far: <HTML> <HEAD> <TITLE>Is it a leap year?</TITLE> </HEAD> <SCRIPT LANGUAGE="JAVASCRIPT>
37
14940
by: mazwolfe | last post by:
I'm new here, so excuse me if my style is incorrect. Can anyone come up with a better method for this calculation? Code: int is_leap(int year) { switch (year % 19) { case 0: case 3: case 6: case 8: case 11: case 14: case 17: return 1; default: return 0;
5
3487
by: jimix | last post by:
here's what i have. using microsoft studio #define _CRT_SECURE_NO_DEPRECATE #include <stdio.h> int main( void ) { int year, b, c, e; b = 4; c = 100;
4
9098
by: jrw133 | last post by:
Hello. So im a little bit stuck on one of my homework questions. heres the question: Write a C Shell Script that performs the following functions. Asks the user to input a year. The script should then calculate whether or not the year is a leap year. The script should caculate whether or not it is a leap year using the following algorithm. A leap year is defined as any year divisible by 4 but not by 100. However, if a year is divisible...
4
4422
by: hallsers | last post by:
Here is the problem i am having: - When a user logs in, on page load it will take the dob of all users in a stored friends list and compare them against the following conditions - To display any friends with a birthday inside the next 3 days, taking into account leap years for some1 born on the 29th of feb to be born on 28th in non leap years and also to display their age with the reminder. Here is code i have picked up so far. 1. ...
0
8504
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8419
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8847
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8643
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7476
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6255
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2840
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2094
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.