js 循環

練習數組

利用for循環計算1 * 2 * 3 * ... * 10的結果 實現思路:spa

   1.定義起始變量 var x=1(由於是乘運算,全部定義變量x=1,若是是加法var x=0) var i  2.for循環code

   var x = 1;
   var i;
   for(i=1;i<=10;i++){console

x=x*i;for循環

}變量

if (x === 3628800) {循環

    console.log('1 x 2 x 3 x ... x 10 = ' + x);
}
else {
    console.log('計算錯誤');
}
請利用循環遍歷數組中的每一個名字,並顯示:
1.定義一組數組 for循環遍歷
Hello, xxx! 實現思路
var arr = ['Bart', 'Lisa', 'Adam'];for(i=0;i < arr.legth;i++){   console.log('hello,'+arr[i]);}
相關文章
相關標籤/搜索