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 Functions Function Parameters Returning Complex Values

Paul Je
Paul Je
4,435 Points

Anybody able to spot out where I've gone wrong? Should I have named the lat and lon in the switch area, "Coordinates"?

func getTowerCoordinates(location: String) -> (Double, Double) { let Coordinates = (lat, lon) switch Coordinates { case "Eiffel Tower": (48.8582, 2.2945) case "Great Pyramid": (29.9792, 31.1344) case "Sydney Opera House": (33.8587, 151.2140) default: (0,0)

}
return (Double, Double)

}

let result = getTowerCoordinates("Eiffel Tower")

functions.swift
// Enter your code below// Enter your code below// Enter your code below

func getTowerCoordinates(location: String) -> (Double, Double) {
    let Coordinates = (lat, lon)
    switch Coordinates {
    case "Eiffel Tower": (48.8582, 2.2945)
    case "Great Pyramid": (29.9792, 31.1344)
    case "Sydney Opera House": (33.8587, 151.2140)
    default: (0,0)

    }
    return (Double, Double)
}

let result = getTowerCoordinates("Eiffel Tower")

2 Answers

Anjali Pasupathy
Anjali Pasupathy
28,883 Points

You have a few issues in your code.

You should be switching on location, not on Coordinates. A switch statement looks at the variable/constant after the keyword "switch", compares the value stored in that variable/constant to the value immediately after the keyword "case", and runs the code after the colon if those values match. If none of the cases match, the switch statement runs the code immediately after the default statement.

switch location { //COMPARE VALUE OF location TO EACH CASE
    case "Eiffel Tower": //RUN THIS CODE IF location == "Eiffel Tower"
    case "Great Pyramid": //RUN THIS CODE IF location == "Great Pyramid"
    case "Sydney Opera House": //RUN THIS CODE IF location == "Sydney Opera House"
    default: //RUN THIS CODE IF NONE OF THE OTHER CASES MATCH
}

If you want, you could return the proper coordinates for each case after each colon. You could also use the variable Coordinates, which should be a variable (not a constant) of type (Double, Double), to store the coordinates and return Coordinates after the switch statement.

I hope this helps!

Paul Je
Paul Je
4,435 Points

thank you Anjali!!!!!