一、题目要求:根据用户输入的年、月、日判断是打鱼还是晒网。代码中使用了isLeapYear函数来判断输入的年份是否为闰年,getDays函数来计算输入日期是一年中的第几天,然后根据计算结果来确定是打鱼还是晒网。最后代码通过弹窗提示用户是打鱼还是晒网。
二、正确的源程序:
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Nauji</title>
</head>
<body><script>function isLeapYear(year){if(year%4==0&&year%100!=0||year%400==0){return true;}else{return false;}}function getDays(year,month,day){var arr = [31,28,31,30,31,30,31,31,30,31,30,31];for (var i = 0; i < month-1; i++) {day+=arr[i];}isLeapYear(year)&&month>2?day++:day;return day;}var year = prompt("请输入年份");var month = prompt("请输入月份");var day = prompt("请输入日期");var n = getDays(year,month,day);if((n%5)<4 && (n%5)>0){alert(year+"年"+month+"月"+day+"日渔夫在打鱼");}else{alert(year+"年"+month+"月"+day+"日渔夫在晒网");}</script>
</body>
</html>
三、运行结果截图: