<script>
/************ 获取当前日期 ************/
var weekArray = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var currentDate = new Date();//获取当前日期
var currentYear = currentDate.getFullYear();//获取年份
var currentMonth = currentDate.getMonth() + 1;//获取月份
var currentDay = currentDate.getDate();//获取天
var currentWeek = currentDate.getDay();//获取星期
document.write(currentYear + "年" + currentMonth + "月" + currentDay + "日" + " " + weekArray[currentWeek] + "<br>");
/************ 计算平均数 ************///成绩
var scoreStr = "你叫什么名字:1230;小花:81;小红:97;小天:7;我叫东方不败:150;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
//拆分成数组
var scoreArray = scoreStr.split(";");
document.write("转化后的数组为:" + scoreArray + "<br>");
var totalNum = 0;
for (i = 0 ; i < scoreArray.length; i ++){
//这里用“ : ” 把每个人的名字和分数分割成数组,因为每个人的名字长度可能不同 分值可能不一样
var tempScoreArray = scoreArray[i].split(":");
//打印出每个人的成绩
document.write(tempScoreArray[0] + "的成绩是:" + tempScoreArray[1] + "<br>");
//或者直接用pop函数取出最后一个值就是 分数
var score = tempScoreArray.pop();
totalNum += parseInt(score);
}
document.write("所有成绩的总和为:",totalNum + "<br>");
document.write("平均值为:", totalNum/scoreArray.length + "<br>");
</script>