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

Had some problems getting this correct. could someone show me what the code should look like and/or explain why.

it said that my areaInFeet value was incorrect

area.swift
// the height and width of a wall
let height = 10.0 // in feet
let width = 12.0 // in feet


let areaInFeet = height / width

2 Answers

Stone Preston
Stone Preston
42,016 Points

the task states: Given the height and width of a wall in inches, calculate the area in feet and assign it to a constant named areaInFeet.

the initial code given is

// the height and width of a wall
let height = 120.0 // in inches
let width = 144.0 // in inches

below is your code:

let height = 10.0 // in feet
let width = 12.0 // in feet


let areaInFeet = height / width

you hardcoded the values in feet, however you are expected to use swift operators to do that.

You need to calculate the area in feet. the general formula for the area of a rectangle is A=wl, in our case its A=wh since its a wall. In your code you computed the quotient instead of the product which is why it told you your value was incorrect

To get the area in feet (well technically square feet), you can compute the product of the height constant converted to feet and the width constant converted to feet. Since there are 12 inches in a foot we can divide the height and width in inches by 12 to get their values from inches and into feet.

let height = 120.0 // in inches
let width = 144.0 // in inches
let areaInFeet = (height / 12) * (width / 12)

for more information on Swift operators, see the Swift eBook

thank you!

Ashleigh Nombre
Ashleigh Nombre
2,308 Points

The answer is very easy you do not have to do the answers above

You need to read the instructions carefully digest the information slowly then proceed

When it give you the height and width

let height = 120.0 // in inches convert them to feet you get 10.0 let width = 144.0 // in inches convert them to feet you get 12.0

let areaInFeet = 120.0