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

Nate Drexler
Nate Drexler
1,883 Points

Code challenge giving me some trouble

I feel like maybe I've overcomplicated the ask here? Feeling a little lost.

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

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

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hey there, Nate Drexler ! Yes, I think you probably are. But let's see if I can walk you through what they want. Ok so we have our results array that they set up for us. Remember doing multiplication tables as a kid? They want us to fill up that array with the results of 6 times 1, 6 times 2 etc all the way up to 10. And they specifically want the temporary constant to be named multiplier. You've named yours number. But every time through your loop you're redeclaring a constant multiplier and assigning it a string. This is having no effect on the results array. Take a look:

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

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

Here, we start with the empty results array. Then every time through the loop we append it with multiplier times 6. So the resulting array will look like this: [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]. Hope this helps and hang in there! :sparkles:

Nate Drexler
Nate Drexler
1,883 Points

This makes some bit of sense. And maybe my brain is just fried, but I don't seem to recall doing any results.append in the last tutorial or in the playground.

Zachary Kaufman
Zachary Kaufman
1,463 Points

Okay so multiplier needs to be the constant in the loop so it would be

for multiplier in 1...10 {}

and for step two, your job is to append results with multiplier * 6 not make a new constant to hold it so your step 2 code will be

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