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 Conditional Statements Working with Switch Statements

Joe Nelson
Joe Nelson
1,331 Points

Not sure what Im doing wrong on this one

I keep getting a message saying to make sure I am capturing all asian capitals. Im not sure what I'm doing wrong?

switch.swift
var europeanCapitals: [String] = []
var asianCapitals: [String] = []
var otherCapitals: [String] = []

let world = [
    "BEL": "Brussels",
    "LIE": "Vaduz",
    "BGR": "Sofia",
    "USA": "Washing D.C",
    "MEX": "Mexico City",
    "BRA": "Brasilia",
    "IND": "New Dehli",
    "VNM": "Hanoi"]

for (key, value) in world {
    switch key {
        case "BEL", "Brussels", "LIE", "Vaduz", "BGR", "Sofia": europeanCapitals.append(value)
        case "IND", "New Dehli", "VNM", "Hanoi": asianCapitals.append(value)
        case "MEX", "Mexico City", "USA", "United States", "BRA", "Brasilia": otherCapitals.append(value)
        default: print("I dont know that one!")

    }
}

2 Answers

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Joe Nelson,

Your corrected code is valid. Try placing it between the comment markers to get the solution to pass. As a general rule, don't edit the code provided by the challenge, including the comments.

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.append(value)
            case "IND", "VNM": 
            asianCapitals.append(value)
            default: 
            otherCapitals.append(value)
    }
    // End code
}

Good Luck

Joe Nelson
Joe Nelson
1,331 Points

ahhh thank you! That solved it

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

You are by far the first to get stuck on this challenge! In fact, I answered this question not long ago at all. Here you can see my full answer and an explanation. https://teamtreehouse.com/community/i-dont-know-what-to-do-or-why-im-wrong

Joe Nelson
Joe Nelson
1,331 Points

I think there may be a bug because I am still getting the same response. Here is the new code, which is identical to yours.

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

let world = [
    "BEL": "Brussels", // europe
    "LIE": "Vaduz", // europe
    "BGR": "Sofia", // europe
    "USA": "Washing D.C", // other
    "MEX": "Mexico City", // other
    "BRA": "Brasilia", // other
    "IND": "New Dehli", // asia
    "VNM": "Hanoi" // asia
]

for (key, value) in world {
    switch key {
        case "BEL", "LIE", "BGR": 
        europeanCapitals.append(value)
        case "IND", "VNM": 
        asianCapitals.append(value)
        default: 
        otherCapitals.append(value)

    }
}