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 trialCristobal Heiss
5,437 PointsHi, I'm dealing with the Challenge Yask 4 of 4 in Swift 3 Collections and Control Flow.
Hi, I'm dealing with the Challenge Yask 4 of 4 in Swift 3 Collections and Control Flow. The first problem is I don't know why when I add 80 to the array using concatenation (arrayOfInts + [80]) the 80 won't remain in my array. The second problem is that after I remove the 6th element (arrayOfInts.remove(at: 5)) I try to create the constant with the discarded value (let discardedValue = arrayOfInts[5]) and it won't work (and the same did work before, in challenge 3 of 4). I have no idea what's going on.
Thanks in advance
// Enter your code below
var arrayOfInts: [Int] = [22,24,28,52,66,72]
arrayOfInts.append(78)
arrayOfInts + [80]
arrayOfInts.remove(at: 4)
let value = arrayOfInts[4]
arrayOfInts.remove(at: 5)
let discardedValue = arrayOfInts[5]
3 Answers
carriebarnett
16,732 PointsOn this line: arrayOfInts + [80]
Instead of using just the "+", try "+=". That should fix both problems for you.
Jeff McDivitt
23,970 PointsHere is the correct answer to this one. As for your question, how do you know that the 80 is not staying on your array?
var arrayOfInts = [1,2,3,4,5,6]
arrayOfInts.append(7)
arrayOfInts += [8]
let value = arrayOfInts[4]
let discardedValue = arrayOfInts.remove(at: 5)
Cristobal Heiss
5,437 PointsThe problem was solved, thanks for your time
Cristobal Heiss
5,437 PointsHi Jeff, thank you very much for the answer. I know it's not staying because I do the exercises in Xcode and after typing the following code:
var arrayOfInts: [Int] = [22,24,28,52,66,72]
arrayOfInts.append(78)
arrayOfInts + [80]
arrayOfInts.remove(at: 4)
let valorem = arrayOfInts[4]
arrayOfInts
When I write arrayOfInts to print the elements it displays all of them but the "80". Not sure why really
Cristobal Heiss
5,437 PointsCristobal Heiss
5,437 PointsThanks carriebarnett, that was it!