+ 1
Can't understand why 4?
var a=[9,5,3]; for (var i = 0; i <3; i++) { a[0]%=a[i]; a[0]+=a[2]; } document.write(a[0])
4 odpowiedzi
+ 13
The output is 3:
1. iteration, i = 0:
9%9=0
0+3=3=a[0]
2. iteration, i=1
3%5=3
a[0]=3+3=6
3. iterarion, i=2
6%3=0
a[0]=0+3=3 -> output 3.
+ 12
@shaldem
This would explain the output 4 ^^
+ 6
Hmm... To me it looks more like 3.
It goes through the iteration and assigns stuff to a[0].
1. a[0] is 9, initially
2. a[0] = a[0] % a[0] = 0
3. a[0] = a[0] + 3 = 3
4. a[0] = a[0] % 5 = 3
5. a[0] = a[0] + 3 = 6
6. a[0] = a[0] % 3 = 0
7. a[0] = a[0] + 3 = 3
3
+ 6
As I remember in challange question was other cicle, there was for(var i=1;i<3;i++)?