+ 4

What is the output of this code and why?

What is the output of this code? a = [2,6,9] a<< 3 a[1]+ = a[0] puts a[1]

23rd Jan 2017, 5:34 PM
1971 ‱ Anas
1971 ‱ Anas - avatar
1 Answer
+ 1
The output is 8 because: a = [2,6,9] #Declares an array a<< 3 #Has nothing to do with the output but it appends to the array a[1] += a[0] # Pretty much sets the new value of the second value in the array by taking this second value and adding it to the first value so a[1] + a[0] puts[1] # just prints the new value
23rd Jan 2017, 5:45 PM
Dawzy
Dawzy - avatar