+ 1
If you put 2 in the answer
the output will be 02468101214161820 if you use the number 2 in the code: var x = 0; for (; x <=20; x +=2) { document.write(x); } someone help me to understand it
7 Respostas
+ 3
Each value of x is written on the screen as you put the code "document.write (x);" within the FOR Loop.
To fix this, just get it out of the for loop:
var x = 0;
for (; x <= 20; x + = 2) {
}
document.write (x);
Output: 22
Hope it helps.
+ 2
Why we must puts 2, not 4 or 5? Me Ask for sololearn example...
x += _
+ 2
the reason for 2 is because the question asks that "even" numbers are printed only. So 0, 2, 4...etc. Your starting variable (initialization) is 0, this then is to be incremented or increased by 2 so long as the condition (is less than or equal to 20) is true which is why your variable increments as follows: x+=2 (same as x = x + 2)
So for example you start at x = 0 (0 is printed), next x = 0 + 2, x now becomes 2
+ 1
x = 0
while
x <=20
:
print
(x)
x += 2
0
because you write document.write(x);
}
INSIDE your loop
0
hello guys. I am sorry but I don't understand why not 3 or 4 or 5...
0 3 6 9 12 15 18 .... ! why would not it be good ?
Thanks.
0
same question