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

Ranak Bansal
Ranak Bansal
1,207 Points

Functions Code Challenge Help

So I ended up finishing and completing the code challenge correctly, but I'm not sure why my code works.

Questions:

Why don't we have two separate variables for temperature in Celsius and temperature in Fahrenheit?

How can temperature be equal to temperature times 9, divided by 5, plus 32?

Lastly, what does 'return temperature' do for us in this case?

BTW, this is the completed and correct code for the challenge

Thanks

functions.swift
// Enter your code below
func temperatureInFahrenheit(temperature: Double) -> Double  {

let temperature = (temperature * 9) / (5) + (32)
return temperature

}

let fahrenheitTemp = temperatureInFahrenheit(temperature:24)

1 Answer

Jeff McDivitt
Jeff McDivitt
23,970 Points

Hi Ranak -

There is no need for two separate values as the input of the function variable temperature is the temperature in celsius For the second question you are letting a constant temperature equal the inout parameter of temperature times 9 divided by 5 plus 32 Finally you are returning that variable