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 trial

iOS Swift Collections and Control Flow Control Flow With Loops For In Loops

christof Kondrup
christof Kondrup
419 Points

how do i append

is the code correct and how do i get the append to work

loops.swift
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
 "\(multiplier * 6)"

}

Hi, the challenge says to append the results of multiplying "multiplier by 6." (multiplier * 6) as typed above is correct. However, to append the value to results you must do the following: for multiplier in 1...10 { results.append(multiplier * 6) } Using double quotes would make it a string. Only use the backslash when putting such a constant or variable inside a string. (Not what we want in this case) Hope this helps!

1 Answer

Hi Christof,

To append to the array you first need to call the append method onto the array (variable name) which looks like this:

results.append()

as for the challenge, you can pass the local variable 'multiplier' directly into the append method all while inside the array and do the multiplication inside the append method.

My code looked like this:

// Enter your code below var results: [Int] = []

for multiplier in 1...10 { results.append(multiplier * 6) }

Hope this makes sense :)