对实现输入年月日知道是该年的第几天的优化

对实现输入年月日知道是该年的第几天的优化

这次使用的其实是对上一篇相同问题解答的一个简化,主要是用到了一个数组去保存月份,然后通过for循环,依次累加总的天数,最后判断是否是闰年并且输入的月份大于2
进行一个加一的操作。
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<script>
		var year=0,
			month=0,
			day=0;
		var total=0;
		var arr=[0,31,28,31,30,31,30,31,31,30,31,30];
		function riqi(year1,month1,day1){
			for(var i=0;i<month1;i++){
				total+=arr[i];
			}
			//若果是闰年,则在总的天数上加1,并且月份必须大于2
			if((year1%4==0 && year1%100!=0 || year1%400==0)&&month1>2){
				total+=1;
			}
			document.write("您的生日是"+year1+"年的第"+(total+day1)+"天"+"</br>");

		}
		//ymd函数用于出生日期的获取
		function ymd(){
			year=parseInt(PRompt("请输入您的出生年份"));
			month=parseInt(prompt("请输入您的出生月份"));
			day=parseInt(prompt("请输入您的出生日期"));
			riqi(year,month,day);
		}
		//函数的调用
		ymd();
		
	</script>
</body>
</html>