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 trialRanak Bansal
1,207 PointsFunctions 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
// 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
23,970 PointsHi 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