iOS Functions in Swift Adding Power to Functions Returning Complex Values

Functions in Swift

func coordinates(for location: String) -> ( Double, Double) { if location == "Eiffel Tower" { return (48.8582, 2.2945) } else if location == "Great Pyramid" { return (29.9792, 31.1344) } else if location == "Sydney opera House" { return (33.8587, 151.2140) } else { return (0,0) }

}

functions.swift
// Enter your code below
func coordinates(for location: String) -> ( Double, Double) {
    if location == "Eiffel Tower" {
        return (48.8582, 2.2945)
    } else if location == "Great Pyramid" {
        return (29.9792, 31.1344)
    } else if location == "Sydney opera House" {
        return (33.8587, 151.2140)
    } else {
        return (0,0)
    }
}

4 Answers

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 57,551 Points

Hi Manoj,

Sydney Opera House has a capital 'O'. Your code is fine if you change that.

But I'd suggest using a switch statement as it is neater:

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)
  }
}

Steve.

I have tried both. Switch statement was fine but if else case was giving me an error. I have been checking over return values but haven’t checked location.

Steve Hunter
Steve Hunter
Treehouse Moderator 57,551 Points

Yeah - the tests are very specific so are case sensitive - changing 'opera' to 'Opera' will fix your if/else code. :+1:

Thanq steve. It was great tutorials. Could you please suggest me some interview questions.

Steve Hunter
Steve Hunter
Treehouse Moderator 57,551 Points

What sort of interview? Are you leading the interview or are you the candidate?

Iam the candidate.. what kind of questions do can i expect.

Steve Hunter
Steve Hunter
Treehouse Moderator 57,551 Points

I'd be asking questions about the job description - provide examples of how you can perform the tasks required, work as a team player, be a self-starter. Then I'd be asking questions about what the candidate knows about the business/company - why will they be a good fit; where do they see their career developing in the business. I'd be asking about the candidate's knowledge of the field the business operates in - how do they remain up to date with developments, how well known are they within the market, what contacts does the candidate bring, how will they be better connected in this role, why does the role represent a career progression, will the candidate's future plans move them away from the business?

Just some thoughts. I've not done interviews for a while but they usually focus on key competencies and then explore how the candidate's experience fits with the role/team/company.

I hope that helps.

Steve.