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 2.0 Collections and Control Flow Control Flow With Loops For In Loops

Christian Kroul
Christian Kroul
9,849 Points

For in loops swift task 2 of 2

This is the error

Your array needs to contain the first 10 multiples. Make sure your range goes from 1 to 10

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

for multiplier in 1...10 {
 print("\(multiplier) times 6 is equal to \(multiplier * 6)")
}

But its correct please tell me what i did wrong

Brian Patterson
Brian Patterson
19,588 Points

I am finding this has not been very well explained. I can understand it as well.

4 Answers

Oh for step 2 it asks you to append to the results array. Your print statement is valid but the question is asking something more in the second step. Here's a walkthrough of the whole problem I did yesterday:

  • Create a for in loop that iterates over a range from 1 to 10. Name the temporary constant "multiplier".
for multiplier in 1...10 {
}
  • Use multiplication to get the multiples of 6 from the loop
for multiplier in 1...10 {
multiplier * 6
}
  • Append it to the given array "results"
for multiplier in 1...10 {
results.append(multiplier * 6)
}

Your code will work for step 1. I just tested it in the challenge and it went through!

Christian Kroul
Christian Kroul
9,849 Points

Yes thank you Ian Han

but step 2 has this error

Your array needs to contain the first 10 multiples. Make sure your range goes from 1 to 10

i guess it can be treehouse's code check thingy

Christian Kroul
Christian Kroul
9,849 Points

oh ok, looks like i did not notice the directions. Thank you very much