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


Abdurahman Sharif
Abdurahman Sharif
1,205 Points

extra credit- writing an equation converting fahrenheit to celsius. please help

sorry guys, really new at this, i'm trying to do the extra credit and i have to write an equation converting fahrenheit to celsius. very basic i'm assuming, but i honestly don't know what to do. please help

2 Answers

J.D. Sandifer
J.D. Sandifer
18,813 Points

Ok, so first you need the calculation for the conversion. A quick google search reveals that we first subtract 32 from the Fahrenheit value and then we multiply by 5/9ths to get the Celsius.

Alright, I'll get you started with some code that assigns a Fahrenheit value to a variable and then prints it out later. You insert the formula to convert it to Celsius in the middle. (Use an Xcode playground or similar so you can see if it works.)

let fahrenheitValue = 32

let celsiusValue =    //here's where you insert the formula using fahrenheitValue


That should print 0 if you got the formula right. If that works, change fahrenheitValue to other numbers to see if they work also. Here are some to try:

212°F = 100°C (change to let fahrenheitValue = 212 and 100 should print out)

104°F = 40°C

68°F = 20°C

-40°F = -40°C

Kristell Fonseca
Kristell Fonseca
Courses Plus Student 284 Points

Vise versa if you want to convert Celsius back to Fahrenheit:

let celcius: Double = 37 // I found that if I didn't specify it was a double it was rounding up and I couldn't see the right number

let fahrenheitValue: Double = (9/5) * celcius + 32