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 trialPatrick Baird
463 PointsBummer code error, not sure why!
Coming back with an error and not sure why that is, any help would be much appreciated :)
// Enter your code below
var arrayOfInts = [4,5,6,7,8,9,10]
arrayOfInts.append(11,14)
arrayOfInts += [13]
2 Answers
Steve Hunter
57,712 PointsHi Patrick,
Further to what Michael put, and he's right, the length of the array after the last challenge was expected to be two more than the first task. However, you used the append
method with two parameters; Swift won't allow that. You can use +=
to add an array of any length to another array but the append
method can only add one element at a time.
var array = [1, 2, 3]
var anotherArray = [4, 5, 6]
array.append(anotherArray) // fails - can't convert [Int] to Int
array += anotherArray // works fine
array.append(10) // works fine
array.append(12, 13) // Fails. Can't use (Int, Int) with append
I hope that helps.
Steve.
Patrick Baird
463 Pointsoh yeah alright cheers
Michael Jones
Python Development Techdegree Graduate 38,554 PointsMichael Jones
Python Development Techdegree Graduate 38,554 PointsHi Patrick,
The code you've written is correct it just they wanted you to add one number for each method. See below -
Hope this helps. And keep up the good work!!
Thanks, Michael J