console
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>求和</title>
<script>
let sum = function () {
let i, j, ret_sum = 0;
for (i = 1, j = 100; i < j; i++, j--) {
ret_sum += i + j;
}
alert(ret_sum);
}
let calculate_date = function () {
let year = 2000, month = 3; day = 3;
let days_total = day;
switch (month-1) {
case 12 : days_total += 31;
case 11 : days_total += 30;
case 10 : days_total += 31;
case 9 : days_total += 30;
case 8 : days_total += 31;
case 7 : days_total += 31;
case 6 : days_total += 30;
case 5 : days_total += 31;
case 4 : days_total += 30;
case 3 : days_total += 31;
case 2 :
if (year % 4 == 0 && year % 100 != 0 ||
year % 400 == 0) {
days_total += 29;
} else {
days_total += 28;
}
case 1 : days_total += 31;
default : break;
}
alert("总共天数:" + days_total);
}
</script>
</head>
<body>
<input type="button" onclick="sum()" value="求和">
<input type="button" onclick="calculate_date()" value="计算某日是一年中的第几天">
</body>
</html>