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 trialCharles Willden
12,357 PointsCan't pass coding challenge even though function executes correctly and follows all directions
I'm getting an error saying "Your function needs to return a tuple containing two Double values"
I cannot for the life of me spot any discrepancies in my function with the instructions. I am definitely getting back a tuple with 2 double values and it seems to be working perfectly in Xcode.
// Enter your code below
func getTowerCoordinates(location: String) -> (lat: Double, lon: Double){
let lat: Double
let lon: Double
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; lon = 0
}
return (lat, lon)
}
2 Answers
Jennifer Nordell
Treehouse TeacherI could be wrong, but I'm of the opinion that your code can and should work outside the challenge. But the challenge does state not to name the doubles being returned. This means that they should not be labeled in the declaration. Also, it's expecting you to return directly from the case statements. You're using your case statements to set a a value to latitude and longitude and then return that, which is clearly what they're not expecting.
Here's my code:
func getTowerCoordinates(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)
}
}
Hope this helps!
Derek Scollon
8,422 PointsI'm honestly not sure why you're code is causing problems, since it seems to work for me too. However, when they say you don't have to name the return values, they seem to insist on them not being named. I solved this in a slightly different way...
// Enter your code below
func getTowerCoordinates(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)
}
}
Charles Willden
12,357 PointsCharles Willden
12,357 PointsI see what you mean, but I did not interpret the instructions as specifying that each case should have a return statement. Similarly, the statement about naming the return values did not seem to expressly says that you should not name them.
Overall, it seems like the instructions are ambiguous and the expected results are over-prescriptive.
Thanks for your help, Jennifer and Derek.