課程
/前端開發(fā)
/JavaScript
/JavaScript入門篇
為啥一開始不判斷score為NULL時(shí),我應(yīng)該返回一個(gè)重新填寫的提醒,而該編碼只能返回score<60分的value
2018-09-18
源自:JavaScript入門篇 2-4
正在回答
語句寫的不對?如果你會(huì)用斷點(diǎn)的就很清晰明了了? 建議如果是新入坑的話?查查怎么打斷點(diǎn)?你這個(gè)else是不符合上面的所有條件輸出的結(jié)果? 判斷語句是有順序的?
當(dāng)什么都不輸入直接點(diǎn)擊確定的時(shí)候,按理說函數(shù)應(yīng)該返回一個(gè)空值,而此時(shí)讓最后一個(gè)else加一個(gè)if判斷,如果score為空則輸出重新輸入,但實(shí)際測試時(shí),不輸入點(diǎn)擊確定會(huì)選擇最后一個(gè)else的情況,不明白這是為什么,此時(shí)按理說應(yīng)該是空值符合else if的條件輸出重新輸入的語句才對,代碼如下:
score =? prompt("請輸入的成績")? ? ? ? ? ? ? ; if(score>=90) { ? ?document.write("你很棒!"); } else if(score>=75)? ? { ? ?document.write("不錯(cuò)吆!"); } else if(score>=60)? ? { ? ?document.write("要加油!");? ? }? ? else if(score==null||score<0)? //什么都不輸入直接點(diǎn)確定應(yīng)返回空值才對 {? ? ? ?document.write("請重新輸入!"); } else { ? ? document.write(score+"要努力了"); }? }
score =? prompt("請輸入的成績")? ? ? ? ? ? ? ;
if(score>=90)
{
? ?document.write("你很棒!");
}
else if(score>=75)
? ? {
? ?document.write("不錯(cuò)吆!");
else if(score>=60)
? ?document.write("要加油!");
? ? }
? ? else if(score==null||score<0)? //什么都不輸入直接點(diǎn)確定應(yīng)返回空值才對
? ? ? ?document.write("請重新輸入!");
else
? ? document.write(score+"要努力了");
? }
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>prompt</title>
? <script type="text/javascript">
? function rec(){
var score; //score變量,用來存儲(chǔ)用戶輸入的成績值。
score =prompt("請輸入你的成績");
? ? ?if(score>=90)
? document.write("你很棒!");
? document.write("不錯(cuò)吆!");
? document.write("要加油!");
? ? else
? ? ? ?document.write("要努力了!");
? </script>
</head>
<body>
? ? <input name="button" type="button" onClick="rec()" value="點(diǎn)擊我,對成績做評價(jià)!" />
</body>
</html>
請把代碼貼出來,謝謝
舉報(bào)
JavaScript做為一名Web工程師的必備技術(shù),本教程讓您快速入門
2 回答var score; score =prompt()
3 回答score
3 回答var score;score=80;不是說這樣規(guī)范嗎?
4 回答為什么score不用聲明了
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2018-09-20
語句寫的不對?如果你會(huì)用斷點(diǎn)的就很清晰明了了? 建議如果是新入坑的話?查查怎么打斷點(diǎn)?你這個(gè)else是不符合上面的所有條件輸出的結(jié)果? 判斷語句是有順序的?
2018-09-20
當(dāng)什么都不輸入直接點(diǎn)擊確定的時(shí)候,按理說函數(shù)應(yīng)該返回一個(gè)空值,而此時(shí)讓最后一個(gè)else加一個(gè)if判斷,如果score為空則輸出重新輸入,但實(shí)際測試時(shí),不輸入點(diǎn)擊確定會(huì)選擇最后一個(gè)else的情況,不明白這是為什么,此時(shí)按理說應(yīng)該是空值符合else if的條件輸出重新輸入的語句才對,代碼如下:
2018-09-19
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>prompt</title>
? <script type="text/javascript">
? function rec(){
var score; //score變量,用來存儲(chǔ)用戶輸入的成績值。
score =prompt("請輸入你的成績");
? ? ?if(score>=90)
{
? document.write("你很棒!");
}
else if(score>=75)
? ? {
? document.write("不錯(cuò)吆!");
}
else if(score>=60)
? ? {
? document.write("要加油!");
? ? }
? ? else
{
? ? ? ?document.write("要努力了!");
}
? }
? </script>
</head>
<body>
? ? <input name="button" type="button" onClick="rec()" value="點(diǎn)擊我,對成績做評價(jià)!" />
</body>
</html>
2018-09-18
請把代碼貼出來,謝謝