0
Please, can anyone explain me why is output 14?
7 Respuestas
+ 2
2 * 4 + 2 - 6 = 4
The for loop loops 10 times. Each time x increases by 1. Thus, x = 14.
+ 2
x=foo(2,4,2,6) it call the foo function
In foo function(2(a),4(b),2(c),6(d)):
it return a*b+c-d
2*4+2-6=8+2-6=10-6=4
Return 4 to x.
The for loop add 1 in each iterate(10 times).
So x =14 in last iteration.
alert(x) //14.
Edit:Loop start from 0, not from 1.
+ 1
Тимур Завьялов the loop starts from 0. Not 1.
0123456789
+ 1
Тимур Завьялов Because it counts from 0 to 9.
0
1.the function foo returns 4.
2.And then the for loop iterates for 10 times.
3.so the answer is 14.
0
Why 10 times, if i<10, means 9 times?
0
Thank you