網頁全端開發JavaScript_0928
let friends = ["Mike","Grace","Jason","Elly"];
for (let i = 0; i < friends.length; i++) {
console.log ( friends [ i ] + "is my friend.");
}
結果
"Mikeis my friend."
"Graceis my friend."
"Jasonis my friend."
"Ellyis my friend."
數學函式 Math Object
Math 物件內建的常用方法 (Methods)
Math.min( )
數值中找出最小值
console.log( Math.min (5,8,19,4,6,10,2) ) // 2
Math.max( )
數值中找出最大值
console.log( Math.max (5,8,19,4,6,10,2) ) // 19
Math.ceil( )
無條件進位、向上取整
console.log( Math.ceil (1.5598) ) // 2
Math.floor( )
無條件捨去、向下取整
console.log( Math.floor (1.5598) ) // 1
Math.round( )
四捨五入取整數
console.log( Math.round (1.5598) ) // 2
Math.random( )
隨機取0~1之間的數,不包含0、1
Math.pow( x , y )
x 的 y 平方
console.log( Math.round (1.5598) ) // 2
Math.sqrt( x )
x 開根號
console.log( Math.sqrt (4) ) // 2
Math.abs( )
取絕對值
console.log( Math.abs ( -5 ) ) // 5
Math 物件內建的常用屬性 (Properties)
*不會更改的常數都用大寫
Math.PI
圓周率
console.log( Math.PI ) // 3.141592653589793
Math.E
自然常數
console.log( Math.E ) // 2.718281828459045
終極密碼分析