码迷,mamicode.com
首页 > Web开发 > 详细

js 循环

时间:2018-04-03 21:55:14      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:思路   strong   练习   nbsp   遍历数组   循环   console   利用   bsp   

练习

利用for循环计算1 * 2 * 3 * ... * 10的结果 实现思路:

   1.定义起始变量 var x=1(因为是乘运算,所有定义变量x=1,如果是加法var x=0) var i  2.for循环

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

x=x*i;

}

if (x === 3628800) {

    console.log(‘1 x 2 x 3 x ... x 10 = ‘ + x);
}
else {
    console.log(‘计算错误‘);
}
请利用循环遍历数组中的每个名字,并显示Hello, xxx! 实现思路
1.定义一组数组 for循环遍历
var arr = [‘Bart‘, ‘Lisa‘, ‘Adam‘];
for(i=0;i < arr.legth;i++){
console.log(‘hello,‘+arr[i]);
}


js 循环

标签:思路   strong   练习   nbsp   遍历数组   循环   console   利用   bsp   

原文地址:https://www.cnblogs.com/hzp-tt/p/8711057.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!