課程
/前端開發(fā)
/JavaScript
/JavaScript進(jìn)階篇
document.write(Math.round((Math.random())*10))?得到的不是整數(shù)是什么原因?
2017-04-18
源自:JavaScript進(jìn)階篇 7-16
正在回答
document.write(Math.round(Math.random()*10)),你多了一對(duì)括號(hào)
小羊3727993 提問(wèn)者
學(xué)習(xí)js 回復(fù) 小羊3727993 提問(wèn)者
沒錯(cuò)啊。案例中也有加那個(gè)括號(hào)。問(wèn)題肯定不是加沒加括號(hào)的事。你可以把提問(wèn)中的代碼復(fù)制過(guò)去,試一下。
Math.random()*10和(Math.random())*10結(jié)果一樣。問(wèn)題不是這個(gè)原因。
"Math.random()"是一個(gè)整體,把它括起來(lái),不會(huì)有影響,就像5*10和(5)*10一樣。
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Math </title><script type="text/javascript">document.write("0-10內(nèi)的整數(shù)有:"+Math.round(Math.random()*10));</script></head><body></body></html>
對(duì)著呢呀
舉報(bào)
本課程從如何插入JS代碼開始,帶您進(jìn)入網(wǎng)頁(yè)動(dòng)態(tài)交互世界
4 回答document.write(Math.round((Math.random())*10));
3 回答究竟是Math.round(Math.random()*10)還是Math.round((Math.random())*10)
5 回答Math.random和Math.round的輸出值不對(duì)是什么原因?
2 回答document.write()怎么打印不出來(lái)整數(shù)
4 回答計(jì)算不大于10的整數(shù)?負(fù)數(shù)算嗎?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2017-04-18
document.write(Math.round(Math.random()*10)),你多了一對(duì)括號(hào)
2017-07-04
沒錯(cuò)啊。案例中也有加那個(gè)括號(hào)。問(wèn)題肯定不是加沒加括號(hào)的事。你可以把提問(wèn)中的代碼復(fù)制過(guò)去,試一下。
Math.random()*10和(Math.random())*10結(jié)果一樣。問(wèn)題不是這個(gè)原因。
"Math.random()"是一個(gè)整體,把它括起來(lái),不會(huì)有影響,就像5*10和(5)*10一樣。
2017-04-18
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
document.write("0-10內(nèi)的整數(shù)有:"+Math.round(Math.random()*10));
</script>
</head>
<body>
</body>
</html>
對(duì)著呢呀