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 trialWilliam Lee
1,316 PointsNot sure how to finish this off.
I know my code is faulty. I just can't pinpoint exactly where and how to fix it. Any help is much appreciated :D
// Enter your code below
func getTowerCoordinates(location: String) -> (Double, Double) {
switch location {
case "EIffel Tower": print(48.8582, 2.2945)
case "Great Pyramid": print(29.9792, 31.1344)
case "Sydney Opera House": print(33.8587, 151.2140)
default: (0,0)
}
return bleh idk help me please.
}
1 Answer
William Li
Courses Plus Student 26,868 PointsHi. There're quite a few issues with the code.
- "EIffel Tower" is a misspelled, only the first letter of Eiffel needs to be capitalized.
- The use of
print()
statements are incorrect here. - Right before the
switch
statement, you need to declare a variable, type (Double, Double), and assign value to the variable at each case in theswitch
statement, on top of that, this variable also serves as the return value of the function. - last but not least, it's essential to properly indent your code block for better readability. Clean code matters.
// Enter your code below
func getTowerCoordinates(location: String) -> (Double, Double) {
var coordinate: (Double, Double)
switch location {
case "Eiffel Tower": coordinate = (48.8582 , 2.2945)
case "Great Pyramid": coordinate = (29.9792 , 31.1344)
case "Sydney Opera House": coordinate = (33.8587 , 151.2140)
default: coordinate = (0,0)
}
return coordinate
}
Hope it helps. Please refer to this lecture for refreshing on the materials
William Lee
1,316 PointsWilliam Lee
1,316 PointsYou're right. Going over the lectures really showed where the gaps in my knowledge! Thank you William.