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 trialTim Wiklund
746 PointsNeed help with challenge task 1 of 1, 2.0 function.
func getTowerCoordinates(location: String) -> cordination: Double {
// 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
var cordination: Double
switch location {
case "Eiffel Tower": cordination = 48.8582; 2.2945
case "Great Pyramid": cordination = 29.9792; 31.1344
case "Sydney Opera House": cordination = 33.8587; 151.2140
default: cordination = 0
return (cordination)
}
}
getTowerCoordinates("Eiffel Toweer")
2 Answers
Martin Wildfeuer
Courses Plus Student 11,071 PointsIn this assignment, you are asked to return a location, which consists of two values, latitude and longitude. This is where tuples come in handy, because they let you return multiple values from a function. (You would still use a framework struct like CLLocation, but for the sake of this assignment it's a tuple)
In your code, you are returning a single Double, when you really need to return a tuple consisting of two Doubles. See the following code and annotations.
// The return type is a tuple, consisting of two Doubles
func getTowerCoordinates(location: String) -> (Double, Double) {
// 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
// Again, cordination is now a tuple (Double, Double)
var cordination: (Double, Double)
// Tuples are assigned as below
switch location {
case "Eiffel Tower": cordination = (48.8582, 2.2945)
case "Great Pyramid": cordination = (29.9792, 31.1344)
case "Sydney Opera House": cordination = (33.8587, 151.2140)
default: cordination = (0, 0)
}
// The return statement should really be the last thing of this function.
// You had it in the switch statement, where only case and default belong.
// (You could also return values from case/default, but what you did is considered
// best practice, that is having only one return statement at the bottom)
return cordination
}
// You had a typo here, "Eiffel Toweer", although
// this was not the reason for the check not to pass
getTowerCoordinates("Eiffel Tower")
As always: please paste your code in a playground, it offers code completion and helps with meaningful warnings and errors.
Hope that helps :)
<small>
Disclaimer: With every post, paste your code and explain what you are having problems with. - If you are getting console errors, post them here as well. - Use an Xcode Playground for coding, it offers autocompletion and displays meaningful warnings and errors. - If code check fails, check the preview button for any errors. - Upvote and/or select a working solution as best answer. Thanks! </small>
Tim Wiklund
746 PointsThanks for the quick respons and good description
Martin Wildfeuer
Courses Plus Student 11,071 PointsSure thing! Glad I could help :)