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

MINJI KIM
MINJI KIM
1,905 Points

i don't know the answer to this questions. cannot understand what question asks

var results: [Int] = [1,2,3,4,5]

for multiplier in 1...10 { print("the multiple is (multiplier) times 6, which is equal to (multiplier*6)") results.append(multiplier*6) }

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("the multiple is \(multiplier) times 6, which is equal to \(multiplier*6)")
results.append(multiplier*6)
}

1 Answer

MINJI, they want an array filled with the results of 6 times each of the numbers in the range 1 through 10 inclusive.

var results: [Int] = []

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

You need a loop counter. Here I name it i. i will be 1 the first time through the loop, 2 the next time, etc.

Then you need a constant, multiplier, to store the results of each multiplication.

Then you need to add (append) the results of the calculation (which is in multiplier) to the results array.

Hope this helps.