<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系好安全带,准备启航</title>
<script type="text/javascript">
//通过javascript的日期对象来得到当前的日期,并输出。
var date=new Date();
var theDate="";
theDate=date.getFullYear()+"年";
theDate+=date.getMonth()+1+"月";
theDate+=date.getDate()+"日";
var week0=date.getDay();
var week="";
switch(week0){
case 0:week="星期一";break;
case 1:week="星期二";break;
case 2:week="星期三";break;
case 3:week="星期四";break;
case 4:week="星期五";break;
case 5:week="星期六";break;
case 6:week="星期七";break;
}
theDate+=" "+week;
document.write(theDate+"<br />");
//成绩是一长窜的字符串不好处理,找规律后分割放到数组里更好操作哦
var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var scoreS=new Array();
scoreS=scoreStr.split(";");
document.write(scoreS+"<br />");
//从数组中将成绩撮出来,然后求和取整,并输出。
var score=new Array();
for(var i=0;i<scoreS.length;i++)
{
score[i]=parseInt(scoreS[i].substring(3));
}
document.write(score+"<br />");
var sum=0;
for(var i=0;i<=score.length;i++)
{
sum+=score[i];
}
document.write("班级总成绩为:"+sum+"<br />");
document.write("班级平均分为:"+Math.round(sum/score.length));
</script>
</head>
<body>
</body>
</html>
Orz,for循环里面的应该写成i<=score.length-1的。_(:зゝ∠)_好低级的错误