+ 1

Could someone explain me how this code works line to line? Thanks.

var a=[9,5,2]; for (var i=1;i<3;i++){ a[0]%=a[i]; } document.write(a[0]);

27th Apr 2018, 11:34 AM
Rastislav Romanec
Rastislav Romanec - avatar
2 ответов
+ 11
Just hand trace it. a[0] %= a[1] // 9 % 5 is 4 // a[0] now stores 4 a[0] %= a[2] // 4 % 2 is 0 // a[0] now stores 0 document.write(a[0]) // writes 0
27th Apr 2018, 11:39 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
thanks
27th Apr 2018, 11:41 AM
Rastislav Romanec
Rastislav Romanec - avatar