0

Please, can anyone explain me why is output 14?

https://code.sololearn.com/W01OSLVsU528/?ref=app

22nd Sep 2020, 10:32 AM
Тимур Завьялов
Тимур Завьялов - avatar
7 odpowiedzi
+ 2
2 * 4 + 2 - 6 = 4 The for loop loops 10 times. Each time x increases by 1. Thus, x = 14.
22nd Sep 2020, 10:41 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 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.
22nd Sep 2020, 10:43 AM
Vadivelan
+ 1
Тимур Завьялов the loop starts from 0. Not 1. 0123456789
22nd Sep 2020, 10:53 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
Тимур Завьялов Because it counts from 0 to 9.
22nd Sep 2020, 10:53 AM
Pon Balaji
Pon Balaji - avatar
0
1.the function foo returns 4. 2.And then the for loop iterates for 10 times. 3.so the answer is 14.
22nd Sep 2020, 10:48 AM
Pon Balaji
Pon Balaji - avatar
0
Why 10 times, if i<10, means 9 times?
22nd Sep 2020, 10:51 AM
Тимур Завьялов
Тимур Завьялов - avatar
0
Thank you
22nd Sep 2020, 10:54 AM
Тимур Завьялов
Тимур Завьялов - avatar