效果图:
任务:
1.通过js的内置对象得到当前日期
var date=new Date();
var year=date.toString().slice(11,15);
document.write(year.toString()+"年");
var month=date.getMonth();
month=month+1;
if(month<10){
document.write("0"+month+"月");
}else{
document.write(month+"月");
}
var day=date.toString().slice(8,10);
document.write(day+"日 ");
var weekday=["日","一","二","三","四","五","六"];
var week=date.getDay();
document.write("星期"+weekday[week]);
2.把字符串放进数组里更好操作
var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var scoreArr=scoreStr.split(";");
3.将成绩从数组中搓出来,求和取整并输出
function getNum(str){
var str1=str.replace(/[*0-9]/ig,"");
return str.replace(str1,"");
}
var num=0, len=scoreArr.length;
for(var i=0;i<len;i++){
var num1=getNum(scoreArr[i]);
num+=Number(num1);
}
num=parseInt(num/len);
document.write("--班级平均分为:"+num);