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 trialMiles Grofsorean
1,345 PointsStruct Method Task 3 of 4
Is anyone else having trouble moving past Struct Method task 3 of 4? The preview isn't showing anything as wrong.
struct Expense {
var description: String
var amount: Double = 0.0
init (description: String) {
self.description = description
}
func calculateTaxes (percentage: Double) -> Double {
return (self.amount * (percentage/100))
var item = Expense (description: "Whatever works")
let amount = 100
}
}
1 Answer
Rick Matsumoto
2,547 PointsThis entire module has been tough for me! I agree with the previous post, but here's the code where I actually got it to work.
struct Expense {
var description: String
var amount: Double = 0.0
init (description: String) {
self.description = description
}
func calculateTaxes(percentage: Double) -> Double {
return (self.amount * (percentage/100))
}
}
var item = Expense (description: "any expense")
item.amount = 100
Chengyu Deng
7,879 PointsChengyu Deng
7,879 PointsThe "amount" is a property of the struct Expense. To get access to this property you should use item.amount instead of just amount. If you just type in "let amount = 100", it just means that you create a constant named amount and its value is 100. Hope this helps!