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 trialTodd Deluca
1,352 PointsTrouble with task 2 of 4 in structs
I am unable to figure out what is wrong with this code. It seems to work in the playground but not for the challenge. Advice would be appreciated.
struct Expense {
var description: String
var amount: Double = 0.0
init(description: String, amount: Double) {
self.description = description
self.amount = amount
}
func calculateTaxes(percentage: Double) -> Double{
return (self.amount * (percentage/100))
}
}
1 Answer
Stone Preston
42,016 Pointsyou added the amount to the init method. dont do that. it already has a default value of 0.0 when it is initialized, and the challenge did not ask for you to do that.
removing the unncessary amount stuff from init ends up looking like this
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))
}
}
only do as much as the challenge asks you to do, if you do extra stuff the challenge wont count it as right