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

Ryan Rassoli
Ryan Rassoli
3,365 Points

Swift Collections and Control Flow Challenge 2

Does anyone know whats wrong with this? It's telling me to have all the multiples of 6, which I think I did, but I'm still getting errors.

loops.swift
// Enter your code below
var results: [Int] = [1,2,3,4,5,6,7,8,9,10]
for multiplier in 1...10 {
    print ("\(multiplier) times 6 is equal to \(multiplier * 6)")
}

3 Answers

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Ryan,

The challenge is telling you first to:

Inside the body of the loop, we're going to use the multiplier to get the multiple of 6. For example, if the multiplier is 1, then the multiple is 1 times 6, which is equal to 6.

That is, compute the value of multiplier times 6.

Once you have a value, append it to the results array. This way once the for loop has iterated over the entire range, the array will contain the first 10 multiples of 6.

That is, append the result of the calculation to the results array.

Inside your loop, you are doing the correct calculation but you are doing it inside a print statement, which the challenge does not want. Your loop does not modify the results array, but it must modify the array to append your calculations. Your results array has been hardcoded with a bunch of numbers that are not results of multiplying a number by 6.

Hope that helps

Alex

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Ryan,

Please be sure to always use Markdown to properly format your code before posting. You can find instructions for how to use Markdown by clicking the 'Markdown Cheatsheet' link between the textbox you type your answer into, and the 'Post answer' button.

From what I can see, you still have hard-coded values in your results variable. The challenge does not tell you to do this. This means that when your loop finishes you will have 20 numbers in your array: the 10 numbers you erroneously hard coded and the 10 numbers that you correctly appended in the loop.

Cheers

Alex

Ryan Rassoli
Ryan Rassoli
3,365 Points

Still a little confusing. From that this is all I'm understanding but I'm still getting errors.

Code: // Enter your code below var results: [Int] = [1,2,3,4,5,6,7,8,9,10] for multiplier in 1...10 { print ("(multiplier) times 6 is equal to (multiplier * 6)") let value = multiplier * 6 results.append(value) }