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

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,021 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,860 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: