Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJintao Zeng
Courses Plus Student 6,343 PointsI did not get concatenating
how to do concatenating
// Enter your code below
var arrayOfInts = [1,2,3,4,5,6]
arrayOfInts.append(8)
let arrayOfInts = [(arrayOfInts) + "9"]
1 Answer
Tobias Helmrich
31,603 PointsHey there,
you can add values to an array by concatenating two arrays which basically means that you're adding one array to another. In this case I'm also using the addition assignment operator (+=) to add the second array to the existing arrayOfInts
and assign it in one step.
Also note that you have to remove the let keyword in the last line of your code because you already created it as a variable and you want to change it.
Like so:
// Enter your code below
var arrayOfInts = [1, 2, 3, 4, 5, 6]
// Using the append method
arrayOfInts.append(7)
// Using concatenation
arrayOfInts += [8]
I hope that helps! :)