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

maths dropout

Hi, I tried several different calculations but I still can't get it right, I'll struggle with the maths. Thanks for any help.

area.swift
// the height and width of a wall
let height = 120 / 12
let width = 144  / 12

let areaInFeet = (Double): height * width

2 Answers

Hi Peter,

There are a few different ways to go about solving this, and your code is very close! The constants for width and height look good. So, to get the area, we just need to multiply them together and assign it to the constant areaInFeet. The question doesn't specify if the area needs to be a double or integer, so we don't need to worry about this conversion (I tested this to make sure).

answer_v1.swift
let height = 120 / 12
let width = 144 / 12

let areaInFeet = height * width

Here are some other solutions, just to help you see how differently code can be written and still provide a correct answer.

answer_v2.swift
let height = 120.0
let width = 144.0

// these could be declared as constants, but I'm arbitrarily choosing var here
var h = height / 12
var w = width / 12

let areaInFeet = h * w
answer_v3.swift
let height = 120.0
let width = 144.0

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

Hope this helps,

Cheers

Hi Robert thanks very much for your help kind help!