閏年判斷加強版占卜程式
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>我的占卜小程式</title>
- </head>
- <body>
- <script type="text/javascript">
- function inputRange(msg,min,max) {
- var value = parseInt(prompt(msg));
- return Math.min(max, Math.max(min, value));
- }
-
- var y = inputRange("請輸入您的出生年:", 1900, 2014);
- var m = inputRange("請輸入您的出生月:", 1, 12);
- // 閏年判斷
- var isLeapYear = (y % 400 == 0) || (y % 4 == 0 && y % 100 != 0);
- // 每月份總日數陣列
- var maxDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
- maxDays[1] = (isLeapYear) ? 29 : 28;
- var d = inputRange("請輸入您的出生日:", 1, maxDays[m - 1]);
- alert("您輸入的日期是:" + y + "/" + m + "/" + d)
- var r = ((y + m) * d) % 3;
- var a = ["吉", "一般", "凶"]
- alert(a[r]);
- </script>
- </body>
- </html>
複製代碼 |