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

Haitham Alam
Haitham Alam
2,685 Points

Hello Does some body know what's wrong here? What's the correct answer?

Hello Does some body know what's wrong here? What's the correct answer?

loops.swift
var results = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

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

results.append = ["multiplier"]

2 Answers

Chase Marchione
Chase Marchione
155,055 Points

Hi Haitham,

  • We don't need to edit the array declaration. We'll fill it with values once our for loop runs and new values are appended to it.

  • Since multiplier is an int and not a string, we don't want to put it in quotes when we make our call to the append method. Also, since we are using it as an argument to a method, we'll put it in parentheses.

var results: [Int] = []

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

Hope this helps!