慕斯2554272
2021-11-06 15:35
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//获取日期
var taday = new Date();
var weekday = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
let time = taday.getDay();
let timeWeek = weekday[time];
let timeYear = taday.getFullYear();
let timeMonth = taday.getMonth();
let timeDate = taday.getDate();
//成绩平均值
var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
let arr = new Array();
arr = scoreStr.split(";")
var count = 0;
var num2 = 0;
for (var i = 0; i < arr.length; i++) {
var num = Number(arr[i].substring(3, 5));
num2 += num;
count++;
}
var b = parseInt(num2 / count);
document.write(timeYear + "年" + timeMonth + "月" + timeDate + "日" + " " + timeWeek + "--班级总分数为:" + b);
</script>
</body>
</html>
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系好安全带,准备启航</title>
<script type="text/javascript">
var Today=new Date();
var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var num=Today.getDay();
var moth=Today.getMonth();
document.write(Today.getFullYear()+"年"+(moth+1)+"月"+Today.getDate()+"日"+"  "+weekday[num]+"<br>");
//通过javascript的日期对象来得到当前的日期,并输出。
//成绩是一长窜的字符串不好处理,找规律后分割放到数组里更好操作哦
var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var sum=0;
var scoreStr_last=scoreStr.split(";");
document.write(scoreStr_last+"<br>");
for (var i=0;i<scoreStr_last.length;i++){
var fen=scoreStr_last[i].split(":");
document.write(fen);
sum+=parseInt(fen[1]);
}
document.write("<br>"+"该班级的平均分为:"+sum/scoreStr_last.length)
//从数组中将成绩撮出来,然后求和取整,并输出。
</script>
</head>
<body>
</body>
</html>
像我一样!
JavaScript进阶篇
468190 学习 · 21891 问题
相似问题