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

Daniel Lambrecht
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree
Daniel Lambrecht
iOS Development Techdegree Student 5,302 Points

ive spent like 45 mins and im still lost... ive also tried to use "BEL ": Brussels": europeanCapitals.append(value)

ive also tried to use "BEL ": Brussels": europeanCapitals.append(value) and all sorts of thing, cant get it to work

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 (key, value) in world {
    // Enter your code below
    switch (key, value) {
    case "BEL", "LIE", "BGR": europeanCapitals.append(value)
    case "USA", "MEX", "BRA": otherCapitals.append(value)
    case "IND", "VNM": asianCapitals.append(value)

    }
    // End code
}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Daniel,

You are on the right track, but there are a couple of things:

First, in the switch statement, you are switching on key, value but are only providing a single case value. This is why the compiler is complaining. In this case, it's 'switching' on a String, String but only being given a String. You only need to switch on the key, not both.

Second, it seems that you may have misunderstood the instructions that state

for the default case, append the values to otherCapitals.

Right now, your switch statement does not have a default clause. So, you should delete your second case and at the end put in a default statement for the others (instead of hard-coding as you have in the second case).

Give it another go with these in mind. I'm sure you'll get it now, but if you're still stuck, post a comment here.

Another hint/tip. When you are doing the coding in the challenges, if there is a preview button, click it. It will give the errors that the checker is encountering and from there you should be able to debug what is wrong.

Keep Coding! And Good Job!

:) :dizzy: