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 trialJericoe States
3,262 PointsRecap: Function 3/3
func temperatureInFahrenheit(temperature: Double) -> Double {
return(temperature * 9) / 5 + 32
}
temperatureInFahrenheit(temperature: 24.0)
let temperatureInFahrenheit(temperature: Double) = fahrenheitTemp
//call the function and pass in a value of 24.0 degrees. Assign the result of the function to a
constant named fahrenheitTemp.
//Why does this code not take? I feel its the simplest thing but I just can't get it.
func temperatureInFahrenheit(temperature: Double) -> Double {
return(temperature * 9) / 5 + 32
}
temperatureInFahrenheit(temperature: 24.0)
let farenheitTemp = temperatureInFahrenheit(temperature: <#T##Double#>)
2 Answers
Jeff McDivitt
23,970 PointsNot sure why you are including the last part of your code
func temperatureInFahrenheit(temperature: Double) -> Double {
return temperature * 9 / 5 + 32
}
let fahrenheitTemp = temperatureInFahrenheit(temperature: 24.0)
Jeff McDivitt
23,970 PointsYes you are correct you basically created a new variable which is ok but not needed
See some Apple documentation
Here they created the variable greeting
func greet(person: String) -> String {
let greeting = "Hello, " + person + "!"
return greeting
}
but it is really not needed because you can just combine and use return
func greetAgain(person: String) -> String {
return "Hello again, " + person + "!"
}
Let me know if that makes sense
Jericoe States
3,262 PointsJericoe States
3,262 Pointsye I figured it out right after I sent my message, thank you
Jenny Dogan
4,595 PointsJenny Dogan
4,595 PointsHey Jeff,
I followed the video and wrote my code a different way and was still able to pass. Can you help answer the following question?
func temperatureInFahrenheit (temperature: Double) -> Double { let fahrenheit = temperature * 9 / 5 + 32 return (fahrenheit) } let fahrenheitTemp = temperatureInFahrenheit (temperature: 24.0)
After looking at your code, I noticed I created an extra constant "fahrenheit", if I did that does that mean the last statement is passing in the value of constant "fahrenheit" into "fahrenheitTemp" where yours is just passing in the result of the calculation into "fahrenheitTemp"? Thanks!