JS学习记录:
1、js的三种提示框:alert、confirm、prompt
2、随机数取值:
- [0,10)和(0,10]:
向下取整:Math.floor(Math.random()*10) //[0,10)
向上取整:Math.ceil(Math.random()*10) //(0,10]
- [0,10]:
向下取整:Math.floor(Math.random()*11) //[0,10]
向上取整:Math.ceil(Math.random()*11)-1 //[0,10]
- [10,20)和[10,20]:
Math.floor(Math.random()*10)+10 //[10,20)
Math.floor((Math.random()+1)*10) //[10,20)
Math.floor(Math.random()*11)+10 //[10,20]
Math.floor((Math.random()+1)*11) //[11,20]
- [-5,5):
Math.floor(Math.random()*10)-5 //[-5,5)
Math.floor((Math.random()-0.5)*10) //[-5,5)
- [-3,10):
Math.floor(Math.random()*13)-3 //[-3,10)
总结:
`Math.random()*(|max|+|min|)+min //[min,max)