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 trialjon kelson
5,149 Pointshi 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
eddyfrankenberger
9,264 PointsI 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
5,149 Pointsjon kelson
5,149 PointsHi 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
5,149 Pointsjon kelson
5,149 Pointsok i re- pasted and for some reason it works . strange how Xcode does that sometimes .many thanks