0
Explanation of the result of this challenge
var count = 0; for (var i = 0; i < 3; i++) { count--; for (var j = 0; j < 3; j++) { count++ } } console.log(count);//returns 6
4 Respostas
+ 4
count=0
values of i =[0,1,2]
values of j=[0,1,2]
first for loop value
I=0
count--
First value = -1
Second for loop
count++ 3 times
-1+1+1+1=2
I=1
count-- -> 2-1 = 1
count++ 3 times
1+1+1+1 = 4
i=2
count-- -> 3
count++ 3times
3+1+1+1 = 6
+ 3
For each i to the count will be j times 1 added, that means 3*3 = 9.
for each i will be from count 1 subtracted, that means 3 times. 9-3 = 6.
+ 1
Bcos the second for loop is in the first. For every iter second for the loop is executed.
I.e
Everytime the first for loop runs, The second loop is executed 3 times
0
Justus what do you mean by count++ 3 times? According to me, it should return 0