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

not understanding why this isn't passing....

This does not produce any errors in Xcode, but I keep getting a bummer message

func temperatureInFahrenheit(temperature: Double)-> Double { var fahrenheit = ((temperature * 9)/5 + 32) return fahrenheit }

let fahrenheitTemp = temperatureInFahrenheit(24.0)

functions.swift
// Enter your code below
func temperatureInFahrenheit(temperature: Double)-> Double {
  var fahrenheit = ((temperature * 9)/5 + 32)
  return fahrenheit 
}

let  fahrenheitTemp = temperatureInFahrenheit(24.0)

2 Answers

Keli'i Martin
Keli'i Martin
8,227 Points

You've got an extra space between let and fahrenheitTemp... I guess that little thing will prevent the task from completing.

Luke Dawes
Luke Dawes
9,739 Points

Nice pick-up, didn't spot that at all.

Keli'i Martin
Keli'i Martin
8,227 Points

It's weird... Something that small shouldn't matter, especially since it doesn't matter in Xcode...

Luke Dawes
Luke Dawes
9,739 Points

Hi Eli,

I tried it your way in Xcode and it worked fine, as you said, but I declared fahrenheit as a constant (let) rather than a variable (var) and removed a set of parentheses from your equation. Like so:

func temperatureInFahrenheit(temperature: Double) -> Double {
    let fahrenheit = (temperature * 9) / 5 + 32
    return fahrenheit
}

let  fahrenheitTemp = temperatureInFahrenheit(24.0)

This seemed to work for me in both Xcode and the Code Challenge. Xcode advised that because we don't really do anything else with the value assigned to the fahrenheit variable apart from manipulate our function argument, it can be safely declared as a constant, which is why I changed it. I also think that the order of operations in Swift allows you to dispense with one of the sets of parentheses you used.

Sometimes, I've noticed that the in-browser simulators can lag behind and will sometimes need a page refresh or even a browser restart, but this passed fine for me. Good luck!

Keli'i Martin
Keli'i Martin
8,227 Points

You can even get rid of the constant completely and just

return (temperature * 9) / 5 + 32