有这样的一个需求完成,创建一个随机点名模块
思路:是有js内置 对象里面的Math.random方法来完成
<script>
function getRandom(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min //得到2个数之间的随机数,且此代码包含这2个数
}
// 随机点名
var arr = ['张珊', '李四', '王二', '兰兰','老张','冬瓜','闰土']
console.log(arr[getRandom(0, arr.length - 1)]);
</script>
这样就可以实现啦