nefu-xiaoshuang  
随机函数
<script>
  封装成一个函数,可以方便调用
        //随机数
        function getRandom (min,max) {
            return Math.floor(Math.random() * (max- min + 1)) + min
        }
        //声明一个数组
        let arr = ['赵云','黄忠','关羽','张飞']
        //生成一个随机数
        let random = getRandom(0,arr.length-1)
        document.write(arr[random])
    </script>
 
内置函数
内置对象是什么
     JavaScript内部提供的对象,包含各种属性和方法给开发者调用
     思考:我们之前用过内置对象吗?
   document.write()
     console.log()
math函数
Math对象是JavaScript提供的一个“数学高手”对象
 提供了一系列做数学运算的方法
 方法有:
 random:生成0-1之间的随机数(包含0不包括1
 ceil:向取整
 floor:向取整
 max:找最大数
 min:找最小数
 pow:幂运算
 abs:绝对值
 Math对象在线文档
随机数
如何生成N-M之间的随机数
Math.floor(Math.random() * (M - N + 1)) + N
posted on 2022-12-03 13:44  nefu-123  阅读(16)  评论(0)    收藏  举报