課程
/前端開發(fā)
/JavaScript
/JavaScript進階篇
還是document.write(Math.round(Math.random()*10));
2015-08-27
源自:JavaScript進階篇 7-16
正在回答
加不加括號對輸出結(jié)果沒有影響
document.write(Math.round(Math.random()*10));
Math.random()產(chǎn)生大于等于0到小于1區(qū)間的隨機數(shù),返回的是數(shù)值,乘以10之后就是產(chǎn)生0到10的隨機數(shù)。所以要在里面乘。
Math.round(Math.random()*10)?? 0~10的隨機數(shù)
舉報
本課程從如何插入JS代碼開始,帶您進入網(wǎng)頁動態(tài)交互世界
3 回答究竟是Math.round(Math.random()*10)還是Math.round((Math.random())*10)
3 回答document.write(Math.round((Math.random())*10))得到的不是整數(shù)
5 回答Math.random和Math.round的輸出值不對是什么原因?
2 回答Math.round()中
4 回答document.write
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關注慕課網(wǎng)微信公眾號
2016-01-18
加不加括號對輸出結(jié)果沒有影響
2015-12-12
document.write(Math.round(Math.random()*10));
Math.random()產(chǎn)生大于等于0到小于1區(qū)間的隨機數(shù),返回的是數(shù)值,乘以10之后就是產(chǎn)生0到10的隨機數(shù)。所以要在里面乘。
2015-08-27
Math.round(Math.random()*10)?? 0~10的隨機數(shù)