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

Matt Steves
Matt Steves
1,954 Points

Won't let me calculate something as simple as an area?

Why won't it let me do this?

area.swift
// the height and width of a wall
let height = 120.0 // in inches
let width = 144.0 // in inches
let areaInFeet = (height * width) * 12

2 Answers

Ryan Field
PLUS
Ryan Field
Courses Plus Student 21,242 Points

I'm not sure why it's not working, but your calculation is a bit off. You'd need to divide each of the numbers by 12 before multiplying them together to get feet, i.e. (height/12) * (width/12). The brackets are unnecessary for the equation, but I think it makes it easier to read.

Seth Kroger
Seth Kroger
56,413 Points

If the length and width are in inches but want the area in square feet then you should either:

  • convert both length and width to feet first by dividing both by 12 before multiplying. -OR-
  • convert the result in square inches to square feet by diving by 144 (12 squared).