Why answer 0 ,why not 4. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why answer 0 ,why not 4.

var x = [9,5,4]; for( var i=1; i < 3 ; i++){ x[0]%=x[i]; } console.log(x[0]);

10th May 2020, 6:27 AM
Md Iftakher Hossain
Md Iftakher Hossain - avatar
6 Answers
+ 4
At i = 1, 9 %= 5 so x[0] becomes 4 At i = 2, 4 %= 4 so x[0] becomes 0 To understand these quiz, you can add console.log to the code block to check the state changes in each iteration, like this : https://code.sololearn.com/W7DS6On5Ut6c/?ref=app
10th May 2020, 6:31 AM
Gordon
Gordon - avatar
+ 3
ChaoticDawg nice attempt, yet note that the for loop starts from 1 instead of 0.
10th May 2020, 6:37 AM
Gordon
Gordon - avatar
+ 3
Gordon whoops nice catch, totally missed that thanks edit: deleted answer, I'm blaming sleepy eyes. lol
10th May 2020, 6:38 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
ChaoticDawg no problem ;-)
10th May 2020, 6:39 AM
Gordon
Gordon - avatar
+ 1
Thanks all. I calculated for i=1, Than stop. What a fool am I??
10th May 2020, 6:50 AM
Md Iftakher Hossain
Md Iftakher Hossain - avatar
+ 1
Md. Iftakher Hossain you'll get better and better :) try some projects
10th May 2020, 7:00 AM
Gordon
Gordon - avatar