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 trialPam Selle
2,123 Pointsswift_lint.swift:14:25: error: 'Double' is not convertible to '()' return (self.amount * (percentage/100)) What?
I get this error in the practice code, but also in my playground ... and then it went away after a few tries. What's happening here?
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) {
return (self.amount * (percentage/100))
}
}
2 Answers
Stephen Whitfield
16,771 PointsThe problem is that you're returning a Double in your calculateTaxes function but you haven't told the compiler that.
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))
}
}
Pam Selle
2,123 PointsThanks! That error confused me, is () a type?
Update: Thank you, Stephen!
Stephen Whitfield
16,771 PointsYes. It is type Void.