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 trial
Brian Murray
1,564 PointsSwift Functions Temperature Challenge
This code works fine in the playground yet the challenge says it cannot be compiled. Any idea why?
func temperatureInFahrenheit(temperature: Double) -> Double {
let fahrenheitTemp = (temperature * 9) / 5 + 32
return fahrenheitTemp
}
temperatureInFahrenheit(24.0)
1 Answer
Steve Hunter
57,712 PointsGlad you got it fixed, Brian.
One little thing - you can do that all in one line:
func temperatureInFahrenheit(temperature: Double) -> Double {
return (temperature * 9) / 5 + 32
}
I don't know if Xcode moans about creating constants/variables that are immediately returned. I know Android Studio does. Being more brief isn't always the best thing to do as having that interim variable can add clarity to some scenarios, especially with a well-chosen name. I guess it is a matter of style & preference rather than right & wrong.
Happy coding!
Steve.
Brian Murray
1,564 PointsBrian Murray
1,564 PointsSolved my own problem: