Math.ceil(Math.random()*7)-1这一句是什么意思啊?详解必采纳


html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Random对象title>
head>
<body>
    本次选择的颜色是:<span id="color">span>
    <input type="button" value="选择颜色" onclick="selColor();">
    
    <script type="text/javascript">
        function selColor(){
            var color=new Array("红色","黄色","蓝色","绿色","紫色","橙色","青色");
            var num=Math.ceil(Math.random()*7)-1;
            //Math.ceil(Math.random()*7)-1这一句是什么意思啊?
            document.getElementById("color").innerHTML=color[num];
        }
    script>
    
body>
html>

//Math.ceil(Math.random()*7)-1这一句是什么意思啊?详解必采纳

Math.random()生成0~1之间的数,Math.ceil表示向上取整,