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 trialZhi Huang
2,046 PointsHaving trouble with this question...
Can someone tell me what i'm doing wrong with my code?
struct Expense {
var description: String
var amount: Double = 0.0
init (description: String) {
self.description = description
}
func calculateTaxes(percentage: Double) -> Double {
var item = Expense(description: "Apples")
item.amount = 100
return self.amount * (percentage/100)
}
// it should accept only one parameter named 'percentage' of type Double
}
2 Answers
Meek D
3,457 PointsThe Error was : instead of Expense we had Expenses
struct Expense {
var description: String
var amount: Double = 0.0
init (description: String) {
self.description = description
}
// add the calculateTaxes method here
// it should accept only one parameter named 'percentage' of type Double
func calculateTaxes(percentage:Double) ->Double {
return self.amount * (percentage/100)
}
}
var item = Expense(description: "Money")
item.amount = 100
Meek D
3,457 PointsYou are on track. It is just that you were declaring the item variable inside of the struct
struct Expenses {
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 = Expenses(description: "Apple")
item.amount = 100
Zhi Huang
2,046 PointsI have tried that. It still wont work :/
Meek D
3,457 Pointsdid you use my answer ?
Zhi Huang
2,046 PointsYes i did, struct Expenses { 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 = Expenses(description: "Apple")
item.amount = 100
Meek D
3,457 Pointscan you repost the question that the task asked please ?
Zhi Huang
2,046 PointsCreate a variable named item and assign it an instance of Expense (remember to use the initializer with the description parameter. Enter any description you like). On the next line assign the amount property a value of 100.
Meek D
3,457 PointsDid you make sure that you don't have many declarations in one line. because the code i gave you works .
Zhi Huang
2,046 PointsI know that the code works, but treehouse is saying that it doesn't? I tried the same code on xCode and it tells me that nothing is wrong with it. So therefore i copied and pasted your code, but it still wont work? Is there a way to report this?
Meek D
3,457 Pointscan you take a screenshot and show me if you can ?
Zhi Huang
2,046 Points[alt text](C:\ "treehouse")
Meek D
3,457 Pointsi can't see the image ? post a link
Meek D
3,457 Pointscan you click on the PREVIEW and send a screenshot ?
Zhi Huang
2,046 PointsWOW!... I really appreciate your help. Thank you so much for helping solve my problem.
Meek D
3,457 PointsGlad I could help ...