JavaScript Source Code 3000: Calculators: Leap Year Calculator
Leap Year Calculator
Is it a leap year? What about in 1900? Get your leap year facts straight with this leap year calculator. Just enter the year you are interested in and the script reports whether it is a leap year or not. Or, enter a range of years and JavaScript will display all the leap years in that range. Awesome!
Check For Leap Year:
Year: is
Leap Years Within A Range:
Start Year:
End year:
JavaScript Source Code 3000: Calculators: Leap Year Calculator
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s). The script is yours!!!
<!-- TWO STEPS TO INSTALL LEAP YEAR CALCULATOR:
1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Anthony Louie -->
<!-- Modified By: Ronnie T. Moore, Editor -->
<!-- Web Site: JavaScript Source Code 3000 -->
<! >
<! >
<!-- Begin
function checkYear(year) {
return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
}
function leap(form) {
year = form.year.value;
var Check1 = parseFloat(year);
for (var i = 0; i < year.length; i++) {
var sLetterCheck1 = year.substring(i, i+1);
if (sLetterCheck1 < "0" || sLetterCheck1 > "9") {
alert("Enter a valid year.");
form.year.focus();
form.year.select();
return;
}
}
if (year < 1582) {
form.result.value = "";
alert("Year must be greater than 1581.");
form.year.focus();
form.year.select();
return;
}
checkYear(year);
if (!checkYear(year)) form.result.value = "not a leap year.";
else form.result.value = "a leap year.";
}
function MakeArray(n) {
if (n <= 0) {
this.length = 0;
return this;
}
this.length = n;
for (var i = 1; i <= n; i++) {
this[i] = 0;
}
return this;
}
var listArray = new MakeArray(160);
var index = 0;
function list(form) {
startyear = form.startyear.value;
endyear = form.endyear.value;
var Check1 = parseFloat(startyear);
var Check2 = parseFloat(endyear);
for (var i = 0; i < startyear.length; i++) {
var sLetterCheck1 = startyear.substring(i, i+1);
if (sLetterCheck1 < "0" || sLetterCheck1 > "9") {
alert("Enter a valid start year.");
form.startyear.focus();
form.startyear.select();
return;
}
}
for (var i = 0; i < endyear.length; i++) {
var sLetterCheck2 = endyear.substring(i, i+1);
if (sLetterCheck2 < "0" || sLetterCheck2 > "9") {
alert("Enter a valid end year.");
form.endyear.focus();
form.endyear.select();
return;
}
}
if (startyear < 1582) {
form.yearlist.value = "";
alert("Start year must be greater than 1581.");
form.startyear.focus();
form.startyear.select();
return;
}
else if (endyear <= startyear) {
form.yearlist.value = "";
alert("End year must be greater than start year.");
form.endyear.focus();
form.endyear.select();
return;
}
else {
index = 0;
for (var i=startyear; i <=endyear; i++) {
if (checkYear(i)) {
listArray[index] = i;
index++;
}
}
}
var allYears;
allYears = "";
for( i = 0; i < index; i++ ) {
allYears += listArray[i] + "\r" + "\n";
form.yearlist.value = allYears;
}
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<BODY>
<center>
<form>
Check For Leap Year:<br>
Year: <input type=text name=year size=4> is <input type=text name=result size=15>
<br>
<br>
<input type=button value="Check Year" onClick="leap(this.form);">
<p>
Leap Years Within A Range:<br>
Start Year:<input type=text name=startyear size=4><br>
End year: <input type="text" name="endyear" size=4><br>
<br>
<input type=button name=listyears value="List Years" onClick="list(this.form);">
<br>
<textarea name=yearlist rows=10 cols=11></textarea>
</form>
</center>
<!-- Script Size: 3.68 KB -->
Wyszukiwarka
Podobne podstrony:
function mcal is leap yearLeap Year TS XVID IMAGiNEfunction mcal is leap yearOświadczyny po Irlandzku Leap Year 2010 CAM LUB H Roman Jakobson in His 85th Yeargap year adventures ebookBlaise S New Year, New Love, New Challenge [Dreamspinner Mistletoe Madness MM] (pdf)Year II SLA #10 The Age Factor in SLAmonths of the yearYear of the Big Thaw Marion Zimmer BradleyYear One SLA #8 Aptitude and Intelligence12 Months in a YearSophomore YearThe Seasons of the YearLife in the year 220018 Year Old Virgin (2009) Komediawięcej podobnych podstron