慕哥0503841
2019-08-12 10:32
var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var sourceArr = sorceStr.split(";");
//document.write(sourceArr);//test
//从数组中将成绩撮出来,然后求和取整,并输出。
var score = new Array();
var sum = 0;
for (var i = 0; i < sourceArr.length; i ++) {
sum += parseInt(sourceArr[i].substr(sourceArr[i].indexOf(":")+1));
//document.write("<br>" + sum);//test
}
document.write("--班级总分为:" + sum);
var score = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var avg=0;
var scoreSpli=score.split(";");
for(var i=0;i<scoreSpli.length;i++){
avg+=parseInt(scoreSpli[i].substr(-2)) ;
}
var pingjun=avg/scoreSpli.length
var mydate= new Date();
var Year=mydate.getFullYear();
var Month=mydate.getMonth()+1;
var day=mydate.getDate();
var ri=mydate.getDay();
var xiqi=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
bb=xiqi[ri];
document.write( Year+ "年" + Month + "月" + day + "日" + bb + " "+ " 班级总分为:" + pingjun)
下面代码如果没用到 , 就没什么用
JavaScript进阶篇
468195 学习 · 21891 问题
相似问题