標籤:迴圈 -- 最大值 abs 通過 最小 ... 隨機數 隨機
隨機函數; Moth.random()
//3、以下通過迴圈給數組每個元素賦值,隨機數。 // Math.random(); 可以隨機0~1之間的任意數 [0,1) // alert(Math.random()); /* 隨機0~10之間的整數(可以隨機到0但是隨機不到10),parseInt(Math.random() * 10) */
Math.abs(要求的值)求絕對值
Math.max(x, y, z) 求最大值可以為多值(js3之前只能為兩個值)。
Math.min(x, y, z ...) 求最小值 可以為多值(js3之前只能為兩個值)。
樣本如下:
//Math.abs(要求的值)求絕對值 alert(Math.abs(100));//100 alert(Math.abs(-100));//100 alert(Math.abs(100-300));//200/*----------------------------------------------------------------*/ //Math.max(x, y, z) 求最大值可以為多值(js3之前只能為兩個值)。 alert(Math.max(100, 300, 200));//200 alert(Math.max(-100, -110));//-100 alert(Math.max(-100, -100));//-100/*---------------------------------------------------------*/ //Math.min(x, y, z ...) 求最小值 可以為多值(js3之前只能為兩個值)。 alert(Math.min(100, 300, 200)); alert(Math.min(-100, -110));//-100 alert(Math.min(-100, -100));//-100
有關Math數學運算的js函數