這個怎么來的,求各位大神幫忙解釋下,謝謝
補充右邊編輯器代碼,在script標簽內,使用random?()方法和round(),計算不大于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(Math.round(Math.random()*10)); </script> </head> <body> </body> </html>
random()*10
這個怎么來的,求各位大神幫忙解釋下,謝謝
2016-10-26
random()產生一個隨機數,此隨機數大于等于0,小于等于1,random()*10后為一個大于等于0小于等于10的隨機數。
2016-10-26
Math.random() 是一個0~1的隨機數,*10的話就his0~10 的數
Math.round()是返回一個四舍五入