課程
/前端開發(fā)
/JavaScript
/JavaScript進階篇
怎么用random()和round()生成一個隨機整數(shù)?
2018-09-27
源自:JavaScript進階篇 7-16
正在回答
? 在? math? 里面【四舍五入? (生產(chǎn)1~10隨機數(shù))】
so:? ?document.write(? ?Math.round(? Math.random()*10 ) );
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
var a=Math.random()*10;
var b=Math.round(a);
document.write(b);
</script>
</head>
<body>
</body>
</html>
document.write(Math.round(Math.random()*10));
Math.round(Math.random()*10) 隨機生成0-10的整數(shù)
本來是先用random(),在random里套round,結(jié)果發(fā)現(xiàn)隨機生成的不是整數(shù)
舉報
本課程從如何插入JS代碼開始,帶您進入網(wǎng)頁動態(tài)交互世界
3 回答怎么實現(xiàn)生成一個隨機整數(shù)?
2 回答隨機數(shù) random()
2 回答可以用round(),random()這兩種方法隨機生成10個不同的數(shù)嗎/用for循環(huán)可以嗎?
1 回答使用random()和round()計算不大于10的整數(shù)
3 回答如何用random()產(chǎn)生0-9的隨機數(shù)
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2018-12-26
? 在? math? 里面【四舍五入? (生產(chǎn)1~10隨機數(shù))】
so:? ?document.write(? ?Math.round(? Math.random()*10 ) );
2018-11-29
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
var a=Math.random()*10;
var b=Math.round(a);
document.write(b);
</script>
</head>
<body>
</body>
</html>
2018-10-30
document.write(Math.round(Math.random()*10));
2018-09-28
Math.round(Math.random()*10) 隨機生成0-10的整數(shù)
2018-09-27
本來是先用random(),在random里套round,結(jié)果發(fā)現(xiàn)隨機生成的不是整數(shù)