+ 1

How I can increase num 80 every time the loop is running?

function chess(){ var arr =[]; for (var i=0;i<4;i++){ var num = 0; arr.push(num); } var newsl = arr[0]+","+arr[1]+","+arr[2]+","+arr[3]; return newsl; } console.log(chess());

19th Jul 2018, 5:48 AM
Nayem
4 Respuestas
+ 1
You could set num to 80 * i
19th Jul 2018, 5:57 AM
Dan Walker
Dan Walker - avatar
+ 1
for(var i=0;i<4;i++) { var num = 80 * i; arr.push(num); } Hope this helps ☺️☺️.
19th Jul 2018, 6:42 AM
Meet Mehta
Meet Mehta - avatar
0
but for that I have to set increment statement to i+=80; and condition to i < value; is there any other way?
19th Jul 2018, 6:05 AM
Nayem
0
no, i increases by 1 for every iteration, so num will be 0, 80, 160, 240 and so on so the increment statement doesn't need to change
19th Jul 2018, 6:19 AM
Dan Walker
Dan Walker - avatar