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

not sure what is wrong with my code

dont know to append the array when I get a value

loops.swift
// Enter your code below
var results: [Int] = [1,2,3,4,5,6,7,8,9,10]

for multiplier in 1...10
{

results.append("\(multiplier * 6)")


}

4 Answers

Anthony Lafont
Anthony Lafont
17,075 Points

OK, I made a mistake, you don't have to put data in the array declaration, and leave it as an empty array.

Here is what you should do:

var results: [Int] = []

for multiplier in 1...10 {
    results.append(multiplier*6)
}
Anthony Lafont
Anthony Lafont
17,075 Points

Hi Tochi,

In the challenge, the variable results is an array of Ints. By appending it with the quotation marks, you're telling the compiler that the data you're appending are Strings, and that's why you get an error. To pass the challenge, you just have to give up the quotation marks

var results: [Int] = [1,2,3,4,5,6,7,8,9,10]

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

Anthony

Hi Anthony, thanks for the reply. I am getting another error now which says 'Make sure the results array constains the first multiple of 6' . I'm not exactly sure why I am getting this

okay it worked. Thanks for your help