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

Tim Seme
Tim Seme
1,664 Points

can someone tell me whats wrong y is it not letting me through

for multiplier in 1...10 { print("(multiplier) times 6 equal to (multiplier * 6)") var results: [Int] = [6] results.append(multiplier) }

loops.swift
// Enter your code below
for multiplier in 1...10
{ print("\(multiplier) times 6 equal to \(multiplier * 6)")
var results: [Int] = [6]
results.append(multiplier)
}

2 Answers

David Papandrew
David Papandrew
8,386 Points

You've got the initial part of the for loop setup right. It's just the code to be executed inside the loop that is wrong.

The gist of it is that with each loop, you will append a value from that iteration to the results array. The value to returned is 6 times the value of the multiplier. On the first loop, the multiplier is 1. Second loop it is 2, etc, etc.

Here is the code:

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

for multiplier in 1...10 {
  results.append(multiplier * 6)
}
David Papandrew
David Papandrew
8,386 Points

What is the exact code you are trying to pass with? I just tried the code I supplied and passed, no problem.

Tim Seme
Tim Seme
1,664 Points

ok so i did this and it still wont let me through because i have to add "mex" and "usa" but they dont go to asian or eurpeanCapitals so where do i add these

var europeanCapitals: [String] = [] var asianCapitals: [String] = [] var otherCapitals: [String] = []

let world = [ "BEL": "Brussels",// eur "LIE": "Vaduz",// eur "BGR": "Sofia",// eur "USA": "Washington D.C.", "MEX": "Mexico City", "BRA": "Brasilia",// eur "IND": "New Delhi",// eur "VNM": "Hanoi"]//asian

// Enter your code below for (key, value) in world { switch(key) { case "BEL", "LIE", "BGR", "BRA", "IND":europeanCapitals.append(value) case "VNM":asianCapitals.append(value) default: otherCapitals.append(value) }

}

Tim Seme
Tim Seme
1,664 Points

I tryed this it told me that the append isn't compatible with integers