can someone explain why this loop does not output "i" in order "0 2 4 6 8 10", but instead it outputs "0 2 6 12 20 30 42 56 72 90" ?
let nmb = 0;
for(let i=0; i<50; i+=2){
nmb+=i;
document.write(nmb + " ");
}
let nmb = 0;
for(let i=0; i<50; i+=2){
nmb+=2;
document.write(nmb + " ");
}
This should solve the problem. The thing is, in your current solution, you are adding i number to the sum. So you add i=2 to nmb, nmb = 2. Then you add i=4 to nmb, nmb = 6, then you add i=6, nmb = 12 etc... You want to add constant value which is 2, not i value.
iat all. You are printingnmbwhich addsito its previous value.