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

Not sure about where to place the constant multiplier in this for loop

Hi! I am not sure where to place the constant multiplier in this loop. This was not discussed during lecture.

Thanks!

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

let multiplier = number * 6 

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

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Denali,

I think you may have misread the challenge instructions and have got a bit off track. You don't need to declare a constant. The first part of the challenge wants you to create the for in loop, and inside there "define" (not declare) a constant to temporarily hold the value of the loop's iterations. So, you need to delete the line with the declaration. Your for in loop is correct, you just need to change the name of the temporary constant from 'number' that you used to 'multiplier' that the challenge asked for.

var results: [Int] = []

for multiplier in 1...10{
}

For the second task, you are asked to append the result to the array results that was created for you. To refresh on the append method, Pasan covers it in this video from earlier in the course. So, you need to delete the print statement you have (the challenge never asked for that) and append each iteration multiplied by 6 to the array. I've provided the code below for you to look at. I hope it makes sense. :)

var results: [Int] = []

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

Keep Coding! :dizzy:

Thank you Jason!

Paul Cox
Paul Cox
12,671 Points

This is the relevant part of the challenge: "...and append the results to an array". It gives you the array results.

Currently you are printing out the value of the 6 times table, but instead, you need to put the values in the results array.