Created
June 4, 2013 16:28
-
-
Save wataru218/5707356 to your computer and use it in GitHub Desktop.
A CodePen by iw3. 閏年(うるうどし)を調べる - 入力した年が閏年か表示します。 参考: http://ja.wikipedia.org/wiki/閏年 1. 西暦年が4で割り切れる年は閏年
2. ただし、西暦年が100で割り切れる年は平年
3. ただし、西暦年が400で割り切れる年は閏年
This file contains hidden or 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
<input type="text" id="year" value="2016">年 | |
<input type="button" value="実行" onclick="execute()"> |
This file contains hidden or 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
function isLeapYear(year) { | |
if (year instanceof Date) { | |
year = year.getFullYear(); | |
} | |
return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0); | |
} | |
function execute() { | |
var value = document.getElementById('year').value; | |
if (isLeapYear(value)) { | |
alert(value + ': 閏年'); | |
} else { | |
alert(value + ': 平年'); | |
} | |
} |
This file contains hidden or 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
body { | |
background: #fdd; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment