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 Swift 2.0 Functions Functions in Swift 2.0 Recap: Functions

Calling a function

I have exhausted myself in the task can I get some help on this one?

functions.swift
func temperatureInFahrenheit(temperature: Double) -> Double {

  return ((temperature * 9) / 5) + 32
}
let fahrenheitTemp

2 Answers

Reed Carson
Reed Carson
8,306 Points

in order to call the function you need to type out the name of the function and pass in the given number for the parameter.

let fahrenheitTemp = temperatureInFahrenheit(24.0)

the first half of this statement is setting a constant named "fahrenheitTemp". the second half is the calling of the function.

*also, you don't need to put any parentheses in your equation. Swift runs the operations in the correct order already. (division multiplication followed by addition subtraction) so you can just say "return temperature * 9 / 5 + 32"

func temperatureInFahrenheit(temperature: Double) -> Double {

  return ((temperature * 9) / 5) + 32
}
let fahrenheitTemp = temperatureInFahrenheit(42.0)
print( fahrenheitTemp )

Robert That works but it has the fahrenheit temp backwards....(24.0) in place of (42.0)