Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Basics (retired) Operators Binary Operators

I get an error message when I typ let areaInMeters = area / 10.764

Hi, I get an error message when I type let areaInMeters = area / 10.764

// Playground - noun: a place where people can play

import UIKit

var x = 1 + 2
let height = 12 // In Feet
let width = 10 // In Feet

let area = height * width

//  1 sq. meter = 1 sq. foot / 10.764
let areaInMeters = area / 10.764

4 Answers

William Li
PLUS
William Li
Courses Plus Student 26,865 Points

Oh, right, that one, you have to do this

let areaInMeters = Double(area) / 10.764

Yeah, I know Amit Bijlani wrote it like this let areaInMeters = area / 10.764 during the video and Playground doesn't seem complaining. I don't have a answer as to why, but consider how new the Swift language is, maybe Apple implemented some new changes to the Swift on the newer version of Xcode.

I suggest this:

let height = 12.0 // Feet
let width  = 10.0 // Feet

let area = height * width
let areaInMeters = area / 10.764

But you can also produce the same result using this:

let height = 12 // Feet
let width  = 10 // Feet

let area = height * width
let areaInMeters = Double(area) / 10.764

Hi, I have checked again my codes. And I saw that I have wrote 12 instead of writing 12.0 .....

Thanks William for Help.