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

jon kelson
jon kelson
5,149 Points

hi my code isn't returning my instance result any idea why ? thanks

import UIKit

class Product { let title: String var price: Double = 0.0

init(title: String, price: Double) {
self.title = title
self.price = price

}

func discountedPrice(percentage: Double) -> Double {
return price - (price * percentage / 100)

}


}

class Furniture: Product {

let height: Double
let width: Double
let length: Double
var surfacearea: Double{
return length * width

}

init(title: String, price: Double, height: Double, width: Double, length: Double) {

    self.height = height
    self.width = width
    self.length = length
    super.init(title: title, price: price)

}

}

let table = Furniture(title: "Coffie Table", price: 300, height: 5, width: 10, length: 10)

table.surfacearea

1 Answer

I think your issue may just be with formatting as your code is correct and does work for me. The title and price stored properties should be on their own line or separated by ;

class Product {
    let title: String
    var price: Double = 0.0

    init(title: String, price: Double) {
        self.title = title
        self.price = price
    }

    func discountedPrice(percentage: Double) -> Double {
        return price - (price * percentage / 100)
    }

}

class Furniture: Product {

    let height: Double
    let width: Double
    let length: Double
    var surfacearea: Double{
        return length * width

    }

    init(title: String, price: Double, height: Double, width: Double, length: Double) {

        self.height = height
        self.width = width
        self.length = length
        super.init(title: title, price: price)

    }
}
jon kelson
jon kelson
5,149 Points

Hi eddyfrankenberger, thanks , the two properties are on there own lines in my original code . sorry they just come out on there own line when pasted. maybe i'll try to re-paste into playground . thanks

jon kelson
jon kelson
5,149 Points

ok i re- pasted and for some reason it works . strange how Xcode does that sometimes .many thanks