0

How is this equal to 10 var arr =[1,2,3,3,2,0] var x = 0 for (var i=1; i<arr.length; i++){ x+= arr[i] } alert(x)

The calculation should be 0 https://code.sololearn.com/WUFk4Avd3YDi/?ref=app

23rd Sep 2018, 12:11 PM
Adebayo Ogunmoriyele
Adebayo Ogunmoriyele - avatar
6 Réponses
+ 1
in your code var=1 makes x+= arr[1] start at second position in array. changing code to var=0 makes x+= arr[0] start at first position in array. ALL arrays start at 0
1st Oct 2018, 7:43 AM
Philip Cattaway
Philip Cattaway - avatar
+ 2
can you insert the code please? press insert on bottom and select your code.
23rd Sep 2018, 12:14 PM
davy hermans
davy hermans - avatar
+ 1
You copied the link in the tag. Rather put it in the question box seems to be a wrong link though https://code.sololearn.com/wufk4avd3ydi/?ref=app
23rd Sep 2018, 12:22 PM
Matthias
Matthias - avatar
+ 1
x += arr[i] adds item i of the arry to x. first 2 than 3, 3, 2 sum = 10
23rd Sep 2018, 3:02 PM
davy hermans
davy hermans - avatar
0
correct thing done. thanks
23rd Sep 2018, 2:53 PM
Adebayo Ogunmoriyele
Adebayo Ogunmoriyele - avatar
0
ok thanks.
23rd Sep 2018, 3:09 PM
Adebayo Ogunmoriyele
Adebayo Ogunmoriyele - avatar