<script type="text/javascript">
var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
//从数组中将成绩撮出来,然后求和取整,并输出。
var myarr = scoreStr.split(';');
var sum = 0;
var averagesum = 0;
for(var i = 0; i<= myarr.length;i++){
sum += parseInt(myarr[i].substr(myarr[i].indexOf(':') + 1));
}
averagesum = sum / myarr.length;
document.write(parseInt(averagesum));
</script>
数组长度弄错了,应该是i<myarr.length
数组长度弄错了,i<=myarr.length