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 trialJosh Knapp
Full Stack JavaScript Techdegree Student 5,665 PointsCan't figure out concatenation of arrays
Here's what I'm trying on this problem...
arrayOfInts = arrayOfInts + 8
the number is arbitrary but isn't that a valid way to concatenate a number to an array?
// Enter your code below
var arrayOfInts = [1,2,3,4,5,6]
arrayOfInts.append(7)
arrayOfInts = arrayOfInts + 8
2 Answers
Ryan Breece
4,160 Pointsvar arrayOfInts = [0,1,2,3,4,5]
arrayOfInts.append(6)
arrayOfInts = arrayOfInts + [7]
Jhoan Arango
14,575 PointsHello:
So far so good, you are doing well. You can use the addition assignment operators ( += ) as an alternative to adding items to an array.
Here is an example:
// Using the assignment operator
var someArray: [String] = ["Treehouse"]
someArray += ["Student"]
// Concatenating
someArray = someArray + ["Hello"]
Good luck, if you have more questions please let me know.
- To help other students learn, you can select the answer the best help you as " Best Answer ".
Josh Knapp
Full Stack JavaScript Techdegree Student 5,665 PointsI realized that my problem was not having brackets around the integer that I was adding. Thanks for your input though!