iOS Functions in Swift Adding Power to Functions Returning Complex Values

Christian Laugesen
Christian Laugesen
930 Points

Help with "Functions in Swift"-challenge

The text says:

In this challenge, we have the following geographical coordinates

Eiffel Tower - lat: 48.8582, lon: 2.2945 Great Pyramid - lat: 29.9792, lon: 31.1344 Sydney Opera House - lat: 33.8587, lon: 151.2140

Declare a function named coordinates that takes a single parameter of type String, with an external name for, a local name of location, and returns a tuple containing two Double values (Note: You do not have to name the return values). For example, if I use your function and pass in the string "Eiffel Tower" as an argument, I should get (48.8582, 2.2945) as the value. If a string is passed in that doesn’t match the set above, return (0,0) Bummer! Make sure you accept a single parameter of type String in your function declaration with the correct argument labels.

Please see my code below. Why is it not working? :)

functions.swift
// Enter your code below
func coordinates(location: String) -> (Double, Double) {

    var coordinates: (Double, Double) = (0,0)

    switch location {
        case "Eiffel Tower": coordinates = (48.8582, 2.2945)
        case "Great Pyramid": coordinates = (29.9792, 31.1344)
        case "Sydney Opera House": coordinates = (33.8587, 151.2140)
    default: coordinates = (0,0)
    }
    return coordinates
}

coordinates("Eiffel Tower")
Christian Laugesen
Christian Laugesen
930 Points

It says "Make sure you accept a single parameter of type String in your function declaration with the correct argument labels".

However, it works just fine in playground.

1 Answer

Alex Koumparos
MOD
Alex Koumparos
Python Web Development Treehouse Moderator 33,478 Points

Hi Christian,

You've described the challenge as requiring: "Declare a function named coordinates that takes a single parameter of type String, with an external name for, a local name of location".

This means that the function signature requires two names, an external ('for') and a local name ('location'). So the signature should look like:

func coordinates(for location: String) -> (Double, Double) {

Because having an external name and local name is not required by the compiler, it is only required by the specifications of the challenge, it is not causing you problems in the playground but is causing you to fail the challenge.

Hope that helps,

Regards,

Alex