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 Functions in Swift Adding Power to Functions Returning Complex Values

Ingo Ngoyama
Ingo Ngoyama
4,882 Points

fuction wont compile

whenI call the coordinates function the ide asks for a ;

functions.swift
// Enter your code below
func coordinates (of location: String) -> (Double, Double)
{
    var lat = 0.0
    var lon = 0.0


    switch location
    {                           
            case "Eiffel Tower": lat = 48.8582; lon = 2.2945
            case "Great Pyramid": lat = 29.9792; lon = 31.1344
            case "Sydney Opera House": lat = 33.8587; lon = 151.2140
            default: lat = 0.0; lon = 0.0


    }

    return (lat, lon)
}
coordinates(of: Eiffel Tower)
Ingo Ngoyama
Ingo Ngoyama
4,882 Points

I got it . Instructor informed me I needed to add "" to my function calls argument as it is a string.

3 Answers

//compile that one!

func coordinates(for location: String)->(Double,Double){ switch location{ case "Eiffel Tower": return(48.8582, 2.2945) case "Great Pyramid": return(29.9792, 31.1344) case "Sydney Opera House": return(33.8587, 151.2140)

default:
    return (0,0)
}

} //call //coordinates(for: "Eiffel Tower")

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Ingo,

You have some issues happening here:

  • You don't need to declare the variables up at the top.
  • You cannot declare multiple values for variables inside of a switch statement (which is causing the syntax error). So, where you have lat = ... lon = inside is not correct.
  • The external and local parameter name being passed into the function is not what the challenge is asking for.
  • The return statement should be inside of the switch statement and applied to each case separately.

I recommend reviewing the video on Switch Statements and then give this challenge another go. You are on the right track, just need to fix up a few things and correct some syntax errors. If you're still having problems, just let us know.

Keep Coding! :)

:dizzy:

Ingo Ngoyama
Ingo Ngoyama
4,882 Points

I didnt know structs yet