var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var myscore=scoreStr.split(";");
var sum=0;
if(var i = 0;i < myscore.length;i++){
sum=sum+parseInt(myscore[i].slice(3,5));
}
document.write(sum/myscore.length);
var sum = 0;
for (var i = 0; i < scoreArr.length; i++) {
sum = sum + parseInt(scoreArr[i].slice(3,5));
}
var avg=sum / scoreArr.length;
document.write(parseInt(avg));
最后document.write(sum/myscore.length);出错
改成var avg=sum / scoreArr.length; document.write(parseInt(avg));
中文是两个字节,所以应该是sum=sum+parseInt(myscore[i].slice(5,7));