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 trialPeter Bozic
453 Pointsmaths 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.
// the height and width of a wall
let height = 120 / 12
let width = 144 / 12
let areaInFeet = (Double): height * width
2 Answers
Robert Richey
Courses Plus Student 16,352 PointsHi 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).
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.
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
let height = 120.0
let width = 144.0
let areaInFeet = (height/12) * (width/12)
Hope this helps,
Cheers
Peter Bozic
453 PointsHi Robert thanks very much for your help kind help!