第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

ror 循環(huán)后面的document.write內(nèi)容無(wú)法顯示嗎

<!DOCTYPE??HTML>
<html?>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>系好安全帶,準(zhǔn)備啟航</title>

<script?type="text/javascript">
var?myd=new?Date();
document.write(myd+"<br>");
var?myday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
document.write("今天是"+myday[myd.getDay()]+"<br>");
??//通過(guò)javascript的日期對(duì)象來(lái)得到當(dāng)前的日期,并輸出。
??//成績(jī)是一長(zhǎng)竄的字符串不好處理,找規(guī)律后分割放到數(shù)組里更好操作哦
??var?scoreStr?=?"小明:87;小花:81;小紅:97;小天:76;小張:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
??var?STR=scoreStr.split(";");
?document.write(STR+"<br>");
document.write("學(xué)生"+"<br>");
?var?score=new?Array();
?var?sum=0;
for(i=0;i<=STR.length;i++)
{
score[i]=parseInt(STR[i].substring(STR[i].indexOf(":")+1));
sum+=score[i];
document.write(Math.round(sum/score.length)+"<br>")};
document.write("學(xué)生"+"<br>");
document.write("123");
??//從數(shù)組中將成績(jī)撮出來(lái),然后求和取整,并輸出。
</script>
</head>
<body>
</body>
</html>

輸出結(jié)果:

Thu Feb 23 2017 13:14:07 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)
今天是星期四
小明:87,小花:81,小紅:97,小天:76,小張:74,小小:94,小西:90,小伍:76,小迪:64,小曼:76
學(xué)生
87
84
88
85
83
85
86
84
82
82

為什么for循環(huán)后面的document.write()語(yǔ)句里面的內(nèi)容都顯示不出來(lái)

正在回答

2 回答

for(i in STR){

score[i]=STR[i].substring(STR[i].indexOf(":")+1);

var num = parseInt(score[i])

sum+=num;

};

document.write(Math.round(sum/score.length)+"<br>")

document.write("學(xué)生"+"<br>");

document.write("123");



直接給score[i]賦值是不正確的寫法,我給你改過(guò)來(lái)了,另外for循環(huán)里不要寫輸出,否則會(huì)輸出全部的計(jì)算結(jié)果,我們只是想要最終總和,寫在外面。

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

yelllowsky 提問(wèn)者

改完最后面的學(xué)生和123還是沒(méi)有顯示出來(lái)啊
2017-02-24 回復(fù) 有任何疑惑可以回復(fù)我~

1:for循環(huán) i<STR.length。因?yàn)閿?shù)組的下標(biāo)是從0開(kāi)始的,如果數(shù)組array=[1,2,3,4,5],ayyay.length就是5,遍歷數(shù)組如果從0開(kāi)始,遍歷到4就可以了。

2:document.write(Math.round(sum/score.length)+"<br>")把這句放在for循環(huán)外面。

1 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

ror 循環(huán)后面的document.write內(nèi)容無(wú)法顯示嗎

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)