课程练习代码语言
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系好安全带,准备启航</title>
<script type="text/javascript">
var myDate = new Date();
var myWeek = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
document.write(
myDate.getFullYear() + "年" +
(myDate.getMonth() + 1) + "月" +
myDate.getDate() + "日" + " " +
myWeek[myDate.getDay()] + "<br/>"
);
var sorceStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var sourceArr = sorceStr.split(";");
document.write("班级每人分数为:" + sourceArr + "<br/>");
var score = 0,
sum = 0,
num = sourceArr.length,
scoreArr = [];
for (var i = 0; i < sourceArr.length; i++) {
score = score + parseInt(sourceArr[i].slice(3,5));
scoreArr = scoreArr.concat(sourceArr[i].slice(3,5));
}
sum = Math.round(score / sourceArr.length);
function sortScore(a,b) {
return b - a;
}
var sortArr = scoreArr.sort(sortScore);
var higth = sortArr[0];
var low = sortArr[sortArr.length - 1];
document.write("班级分数由高到低为:" + sortArr + "<br/>");
document.write("班级总分为:" + score + "<br/>");
document.write("班级人数为:" + num + "<br/>");
document.write("班级人数最高分为:" + higth + "<br/>");
document.write("班级人数最低分为:" + low + "<br/>");
document.write("班级平均分为:" + sum);
</script>
</head>
<body>
</body>
</html>