Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift 2.0 Functions Functions in Swift 2.0 Recap: Functions

i need halp on this

i don't know how to do dis

functions.swift
temperature = 2.0
func temperatureInFahrenheit(temperature){
print(temperature)
}

1 Answer

Alex Millius
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Millius
iOS Development Techdegree Student 5,468 Points

It may be confusing since the result of the first part of this challenge doesn't do anything.

Let's take the description of the challenge part by part.

  1. "Declare a function named temperatureInFahrenheit." -> you have to declare a function, not a variable or a constant:

func temperatureInFahrenheit(){ }

  1. "The function should take a single input named temperature" -> temperature is the name of the input parameter, not of a variable or a constant. the input are in parentheses:

func temperatureInFahrenheit(temperature ){ }

  1. " of type Double" -> you have to specify the type of your parameter, in this case, Double:

func temperatureInFahrenheit(temperature : Double){ }

  1. " and has a return type of Double." -> your function return something, in this case a Double:

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

  1. "For now, to make the function pass, simply return the value of the temperature parameter from the function." -> you have to return the function parameter, which is temperature. Since temperature is a Double, it correspond to your return type:

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