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

Tijn-Pieter Koopman
Tijn-Pieter Koopman
4,128 Points

I am not sure what I am doing wrong here. Can someone help?

When I check this it says: Remeber to append the values from each case statement to the correct array. What do I do?

operators.swift
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 capital in world {
    switch capital {
    case "BEL", "LIE", "BGR": europeanCapitals.append(capital)
    case "IND", "VNM": asianCapitals.append(capital)
    default: otherCapitals.append(capital)
    }
}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Tijn-Pieter Koopman

You are very close. The syntax is correct; however, the switch is not switching on the correct value. Remember, the dictionary contains key: value pairs, but right now you are trying to switch on the pair instead of just the key. With that in mind, when you are appending, you should also be appending the value to the new array.

I've provided a pretty detailed answer to a previous post if you'd like to have a look.

Nice work! :) :dizzy: