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 trialAllison Larson
3,177 PointsDeclare a function named temperatureInFahrenheit. The function should take a single input named temperature of type Doub
Declare a function named temperatureInFahrenheit. The function should take a single input named temperature of type Double and has a return type of Double.
For now, to make the function pass, simply return the value of the temperature parameter from the function. In the next task, we'll add more code to the body.
I keep getting an error of unexpected non void return value
// Enter your code below
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Allison,
Without seeing your code, I'm not able to explain why you are receiving that error.
The challenge wants a function declared with one parameter called "temperature" that will take the type of double. Then you have to declare the return type (using the -> symbol) ... also of type double. Then inside the code block just return the parameter passed into the function.
func temperatureInFahrenheit(temperature: Double) -> Double {
return temperature
}
I hope that helps.
Wei Wei Shen
808 PointsWei Wei Shen
808 PointsDear Jason Anders, why can't I just :
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsHi Wei Wei Shen
I don't have a technical answer for you, so I will give what I believe to be a simple answer. Swift likes to be told what type the function is going to return. Swift is more or less build off of Objective-C, where you always specify type. With that, that's why the instructions for the challenge included what
type
needed to be returned.See, you could have the function take in a
Double
as this one does, but then have it return anInt
(after some code inside of the function). So really, Swift just wants to know what to expect.