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

MIchael Montoya
MIchael Montoya
3,222 Points

Functions Recap. Task 1 of 3.

Why is this wrong?

func temperatureInFahrenheit() -> Double { var temperature = 5 return temperature }

functions.swift
// Enter your code below
func temperatureInFahrenheit() -> Double {
var temperature = 5
return temperature
}

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Well there's a couple of things. First and foremost, this function is supposed to accept a value sent by other code. In this case, it will be Treehouse that sends in the value and we have NO clue what it is. In fact, they can test different values to make sure your code works. Currently you return a double, but you accept nothing. Take a look at the function definition you need:

// Enter your code below
func temperatureInFahrenheit(temperature: Double) -> Double {
return temperature
}

Here I declared a function that takes a Double named temperature and returns a Double. When Treehouse sends their number (whatever it may be) it will always be referenced to as temperature inside the function. So there will be no need for your var temperature = 5 after that. Hope that helps!