Created
September 5, 2012 22:24
-
-
Save rvbsanjose/3646322 to your computer and use it in GitHub Desktop.
Leap Year in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Leap Year in JavaScript</title> | |
<style type="text/css"> | |
* { margin: 0 auto; width: 960px; background-color: blue; } | |
#text_where { | |
color: white; | |
font-weight: bold; | |
text-align: center; | |
font-size: 40px; | |
margin-top: 25px; | |
} | |
#time_output { | |
color: white; | |
font-weight: bold; | |
font-size: 30px; | |
text-align: center; | |
margin-top: 185px; | |
} | |
#get_year { | |
text-align: center; | |
font-size: 40px; | |
font-weight: bold; | |
color: white; | |
} | |
#year { | |
font-size: 38px; | |
color: white; | |
width: 105px; | |
text-align: center; | |
margin-top: 25px; | |
border: 2px solid white; | |
} | |
#submit { | |
width: 250px; | |
color: white; | |
font-size: 38px; | |
text-align: center; | |
border: 2px solid white; | |
background-color: red; | |
} | |
</style> | |
<script type="text/javascript"> | |
var $ = function(id) { return document.getElementById(id); } | |
function leap_year() { | |
var year = $("year"); | |
var ans; | |
var leap = year.value % 4 == 0 && year % 100 != 0 || year % 400 == 0 | |
if (leap == true) | |
ans = year.value + " is a leap year!"; | |
else | |
ans = year.value + " is not a leap year!"; | |
$("text_where").innerHTML = ans; | |
} | |
function timeInterval() { | |
setInterval("displayTime()", 1000); | |
} | |
function displayTime() { | |
var time = new Date(); | |
var tm = time.toLocaleTimeString(); | |
var str = "The current time is: " + tm; | |
$("time_output").innerHTML = str; | |
} | |
</script> | |
</head> | |
<body onload="javascript:timeInterval();"> | |
<div id="time_output"></div> | |
<div id="get_year"> | |
What year would you like to check for leap? <br /> | |
<input type="text" id="year" name="year" /> | |
<input type="button" id="submit" value="Sumbit" onclick="leap_year();" /> | |
</div> | |
<div id="text_where"></div> | |
</body> | |
</html> |
This string has error:
var leap = year.value % 4 == 0 && year % 100 != 0 || year % 400 == 0
Use this:
var leap = year.value % 4 == 0 && year.value % 100 != 0 || year.value % 400 == 0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Bro!! 💯