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 trialMicah Doulos
17,663 PointsThis ? requires a technique we were not taught in order to answer. Put integers gathered from a for in loop to an array.
In XCode I've created this code:
/* var results: [Int] = [1,2,3]
for multiplier in 1...10 { results=[multiplier * 6] }
print(results) */
My code replaces the array of 1,2,3 with the last multiple of 1...10 which is 10 * 6 = 60. The challenge requires assigning the results of the multiplying integers in order to the array. However the instructional videos only show how to print the results of such math. The videos don't show how to save the results as they come and go.
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
print(multiplier * 6)
}
2 Answers
Jennifer Nordell
Treehouse TeacherHi Micah! The technique for adding items to arrays was shown a few videos back in this video starting at about 0:42 into the video. But it might have been a while since you saw this video.
Instead of printing the result it wants the result put into the empty array. Take a look at the link about the append method and see if you can work it out. But if you're still stuck, let me know!
Micah Doulos
17,663 PointsI saw it since and have answered another student's question about it. I'll paste my answer here. Thanks Jennifer!
This question requires remembering how to append to an array learned earlier in the track. For a refresher it is arrayYouWantAppended.append(newArrayOrValues). In my example, the multiplication by 6 can take place inside of the parenthesis.
-= Spoiler below =-
-= Spoiler below =-
-= Spoiler below =-
The correct answer to this question is:
var results: [Int] = []
for multiplier in 1...10 {
results.append(multiplier * 6)
}
And if you type print(results) in to xcode, then you'll see the array has been updated.