代码如下: var sorceStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76"; myarr = new Array(); sorce = new Array(); var sum = 0; myarr = sorceStr.split(";"); for(i=0; i<myarr.length; i++) sorce[i] = myarr[i].substr(3); for(j=0; j<sorce.length; j++) sum = sum+parseInt(sorce[j]); average = Math.floor(sum/sorce.length); document.write("班级平均分为:"+average);---------------------------------------------------------------------- var sorceStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76"; myarr = new Array(); sorce = new Array(); var sum = 0; myarr = sorceStr.split(";"); for(i=0; i<myarr.length; i++){ sorce[i] = myarr[i].substr(3);} for(j=0; j<sorce.length; j++){ sum = sum+parseInt(sorce[j]); average = Math.floor(sum/sorce.length); document.write("班级平均分为:"+average)};
4 回答
溜达溜达
TA贡献106条经验 获得超19个赞
标题应该改为“大家来找茬”
上边的代码只循环了
sum = sum+parseInt(sorce[j]);
下边的代码循环了
sum = sum+parseInt(sorce[j]); average = Math.floor(sum/sorce.length); document.write("班级平均分为:"+average)
- 4 回答
- 0 关注
- 1808 浏览
添加回答
举报
0/150
提交
取消