在document.write里直接调用函数的问题
document.write(cloc()+"--班级总分为:" + num + "<br>");
为什么这样写函数后会多个undefined呢?
这是代码:
function cloc() {
var todays = new Date();
var year = todays.getFullYear();
var mon = todays.getMonth()+1;
var day = todays.getDate();
var week = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var today = todays.getDay();
document.write(year + '年' + mon + '月' + day + '日' + week[today]);
}
var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var score = scoreStr.split(";");
var num = 0;
for (var i=0; i< score.length; i++) { //循环score数组
num += parseInt(score[i].substr(score[i].indexOf(":")+1));
}
cloc();
document.write("--班级总分为:" + num + "<br>");
cloc();
document.write("--班级平均分:" + Math.round(num/score.length));