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
6 Antworten
+ 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
+ 2
can you insert the code please?
press insert on bottom and select your code.
+ 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
+ 1
x += arr[i] adds item i of the arry to x.
first 2 than 3, 3, 2
sum = 10
0
correct thing done. thanks
0
ok thanks.