先来一张思维导图:
Math内置对象产生随机数和随机点名需求的实现:
function getRandom(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}//Math.floor()为向下取整(例Math.floor(3.6)输出的结果为3)
console.log(getRandom(1,10));
//随机点名
var uname = ['tom','jerry','rose','brown'];
console.log(uname[getRandom(0,uname.length-1)]);//对数组下标进行操作
Date