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

Stuck on Functions Code Challenge.

The code challenge keep asking me to "Make sure you're specifying the correct return type for the function and returning the correct value!" I'm a slightly confused as to what it means "correct return type" If someone could explain what I've missed I'd really appreciate it. Thank you for your time.

functions.swift
// Enter your code below
func temperatureInFahrenheit (temperature: Double) -> Int {
  let temperature = 78
  return temperature
}
Greg Kaleka
Greg Kaleka
39,019 Points

Hey Sean,

Jason's answer is correct. One other key point, though: since this is in a function definition, this means later in your code you (or someone else) will be passing a number into the function. By explicitly creating a constant named temperature inside the function, you're effectively ignoring future you's input. Here's what would happen:

dontDoThis.swift
func temperatureInFahrenheit (temperature: Double) -> Int {
  let temperature = 78
  return temperature
}

let fTemp = temperatureInFahrenheit(10.0)

print(fTemp) // 78!

Hope this makes sense!

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,692 Points

Hey Sean,

You've almost got it, there is just a couple of things.

First, you are getting that error, because the challenge wants the return type to be Double and you have coded a return type of Int (the declaration after the -> is the return type.

Second, the challenge didn't ask for you to declare a value for the variable temperature (and challenges are very picky). It just wants you to return it.

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

Hope that helps. :) :dizzy: