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 trialMatthew Turk
6,155 PointsBummer! The taxes variable was expected to be a Double, but it wasn't!
On the last objective of the final Challenge of Structs and Their Methods, I thought I was all set with this code:
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)
}
// it should accept only one parameter named 'percentage' of type Double
}
var item = Expense(description: "Something")
item.amount = 100
var taxes = Expense.calculateTaxes(item)
Unfortunately, it told me the the taxes variable I declared had to be of type double. I checked for complier errors and there were none. I'm confused and any help would be appreciated.
1 Answer
Laurence Bowe
6,222 PointsHey, Don't worry about being confused we all get this moment some point in learning swift!!!
Here is the code:
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) } // it should accept only one parameter named 'percentage' of type Double
}
var item = Expense(description: "Something") item.amount = 100 var taxes = item.calculateTaxes(7.5)
Hope that helps and goodluck!!!