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

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!