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 trialDenny Louis
10,885 PointsRemeber to append the values from each case statement to the correct array
I'm getting a message when I submit my code saying "Remeber to append the values from each case statement to the correct array".
I've tested my code in a Swift Playground and it doesn't say I have any errors and the results array has all of the values inside, not sure what I am doing wrong?
I had exactly the same problem with the previous code challenge so I'm starting to think maybe it's a bug in the course (or I'm just wrong)?
var europeanCapitals: [String] = []
var asianCapitals: [String] = []
var otherCapitals: [String] = []
let world = [
"BEL": "Brussels",
"LIE": "Vaduz",
"BGR": "Sofia",
"USA": "Washington D.C.",
"MEX": "Mexico City",
"BRA": "Brasilia",
"IND": "New Delhi",
"VNM": "Hanoi"]
for (key, value) in world {
// Enter your code below
switch key {
case "BEL", "LIE", "BGR": europeanCapitals += [value]
case "IND", "VNM": asianCapitals += [value]
default: otherCapitals += [value]
}
// End code
}
1 Answer
Alexander Davison
65,469 PointsYour code looks fine, maybe try using .append()
instead of the concatenation operator?
Here:
for (key, value) in world {
// Enter your code below
switch key {
case "BEL", "LIE", "BGR": europeanCapitals.append(value)
case "IND", "VNM": asianCapitals.append(value)
default: otherCapitals.append(value)
}
// End code
}
Good luck! ~alex
Denny Louis
10,885 PointsDenny Louis
10,885 PointsThanks Alex, it worked!
Do you know why the append method worked, while the concatenation wasn't accepted? I'd just like to know so I don't make the mistake again. It's pretty confusing since it worked for me in Xcode.
Thanks again :)
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsI think it's just because Code challenges are picky.
Keep trying different ways and you will get it :)