要使用方法必须先要实例化一个对象,这个不要忘了,但是Math这个对象不用它是内置对象,直接可以用
var my_obj=new xxxx();
alert(Math.random()) ;//(0到1)的随机数
alert(Math.round(2.4));//四舍五入
- 产生0到10的随机数
var num=Math.random()*10;
num=Math.round(num)
document.write(num)
document.write(Math.pow(2,3)) // 2的3次方