iOS Functions in Swift Adding Power to Functions Returning Complex Values

Peter Reichl
PRO
Peter Reichl
Pro Student 7,825 Points

Functions in Swift Challenge: Return a complex value

My code works in a playground, but I get a non-specific error message. When I click on preview to see the errors, the output is empty. What am I missing?

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

    var lat: Double = 0.00
    var lon: Double = 0.00

    switch location {
    case "Eiffel Tower":
        (lat = 48.8582, lon = 2.2945)
    case "Great Pyramid":
        (lat = 29.972, lon = 31.1344)
    case "Sydney Opera House":
        (lat = 3.8587, lon = 151.2140)
    default:
        (0,0)
    }
    return (lat, lon)
}
coordinates(for: "Eiffel Tower")

3 Answers

Jennifer Nordell
MOD
Jennifer Nordell
Treehouse Moderator

Hi there! You're actually doing fantastic. The problem here is simply a pair of typos. The latitude for "Sydney Opera House" and "Great Pyramid" are incorrect, so it's getting back a faulty latitude.

The latitude for "Sydney Opera House" is supposed to be 33.8587 but you typed 3.8587. Note the missing 3 at the beginning. On the "Great Pyramid", the latitude should be 29.9792 but you typed 29.972. Note the missing 9 towards the end between the 7 and 2.

No problems here besides a couple of typos and that happens to those who think faster than they type :smiley:

Hope this helps! :sparkles:

Peter Reichl
PRO
Peter Reichl
Pro Student 7,825 Points

Yes, very good advice: I need to slow down some times. It works perfectly now. Thanks for the quick response, Jennifer!

NAVEED CHOWDHURY
NAVEED CHOWDHURY
1,142 Points

Thanks for posting this , although this is not part of the challenge I want to know how you can make the code non sensitive to both Upper Case and Lower Case when the user writing the input.