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

what did i do wrong here?

help

switch.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 {
    case "BEL", "LIE", "BGR" : europeanCapitals.append(Value)
    case "VNM", "IND" : asianCapitals.append(Value)
    Default : otherCapital.append(Value)
    }
    // End code
}

2 Answers

Albert, you need to be really careful about upper and lower case, and spelling.

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

Note that value is not capitalized, nor is default. Further, it's otherCapitals plural!

Anjali Pasupathy
Anjali Pasupathy
28,883 Points

The only things you did wrong here are typos. Swift is case-sensitive, so you need to watch out for that.

You have three main typos in your for in loop: (1) you need to either uncapitalize all the "Value" variables you're appending to each array, or you need to capitalize "value" at the beginning of your for loop; (2) you need to uncapitalize "Default"; and (3) you need to put an "s" at the end of "otherCapital" in your switch statement.

for (key, value) in world { // THIS "value" DOES NOT MATCH THE OTHER "Value"s YOU'RE APPENDING TO EACH ARRAY
    // Enter your code below
    switch key {
    case "BEL", "LIE", "BGR" : europeanCapitals.append(Value)
    case "VNM", "IND" : asianCapitals.append(Value)
    Default : otherCapital.append(Value) // "Default" NEEDS TO BE "default" AND "otherCapital" NEEDS TO BE "otherCapitals"
    }
    // End code
}

I hope this helps!