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 Basics (retired) Operators Binary Operators

Peter M Kreppein
Peter M Kreppein
15,120 Points

I did declare a constant areaInFeet...

The code will work in XCode but not here, or perhaps I'm missing something.....

area.swift
let height = 120.0 // in inches
let width = 144.0 // in inches
let heightFeet: Double = height / 12
let widthFeet: Double = width / 12
let areaInFeet: Double = heightFeet * widthFeet

1 Answer

Peter, the treehouse code challenge compiler will not recognize the calculations when they are stored in different variables in this case.

Here is the correct code for the areaInFeet constant:

 let areaInFeet = (width / 12) * (height / 12)

Although the grouping symbols (parenthesis) are not required, they can become very helpful when performing long calculations with programming because they make your calculations in a much more readable format.

If you have any questions, feel free to ask!