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

iOS Functions in Swift Functions in Swift Recap: Functions

Alex Deltomme
Alex Deltomme
1,628 Points

Need help for Challenge Task 2/3 (Recap: Functions)

This is probably completely wrong, but could someone correct this and give me a hint on how to complete it? Not the solution, just a hint would be nice.

functions.swift
// Enter your code below
func temperatureInFahrenheit(temperature : Double) -> Double {
var Celcius = 5
var Fahrenheit = 5 * 9 / 5 + 32
return Fahrenheit
}

3 Answers

Dan Lindsay
Dan Lindsay
39,611 Points

Hey Alex,

I don’t really know how to help more without giving the answer, so I will just try to give a good explanation of the answer.

I assume you got the first task done, and if not, it would look like this:

func temperatureInFahrenheit(temperature: Double) -> Double {
  return temperature
}

Let’s take the rest one step at a time. In the second part of the challenge, they ask us to get rid of the existing return statement. So now our function looks like this:

func temperatureInFahrenheit(temperature: Double) -> Double {

}

It is implied that the temperature parameter of our function is going to be in Celcius, as we don’t convert Fahrenheit to Fahrenheit, and there is no mention of Kelvin(the only other measurement of temperature that I know of). Knowing that, we will not need to create any other variables inside our function. All we need to do is return temperature converted to Fahrenheit, like so:

func temperatureInFahrenheit(temperature: Double) -> Double {
  return (temperature * 9) / 5 + 32
}

and this part of the challenge is complete. Sorry I had to give the answer, but I couldn’t think of another hint for you. Still, I hope this explanation helps you out.

Dan

Alex Deltomme
Alex Deltomme
1,628 Points

Now I understand, thanks a lot!

Dan Lindsay
Dan Lindsay
39,611 Points

Hi Alex,

A couple of hints for you. First, your function has a parameter named temperature, which you are not using. Also, do you need to create any other variables to solve this challenge, or can it be done without any extra variables?

Hope this helps!

Dan

Alex Deltomme
Alex Deltomme
1,628 Points

I'm still pretty unsure on what to do... :/

Alex Abid
PLUS
Alex Abid
Courses Plus Student 810 Points

Hi Dan, quick question on your answer. In the problem itself it says to "return fahrenheit" and convert celsius.

I'm thankful for the correct answer but why is it that we don't need to actually use those titles within the code at all?