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 trialColin Adler
2,225 PointsQuiz broken?
I have tried this on multiple computers, PC and Mac. Whenever I get to the second part of the quiz, no matter what I do it always throws an error. When the same code is thrown in Xcode, it works fine. I was wondering if there was a problem with the quiz, or I am missing something.
Thanks in advance, Colin
edit: I would like to add that whenever I go into the debug tab, it does not show anything
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) {
self.amount * (percentage/100)
}
}
2 Answers
Stone Preston
42,016 Pointstask 2 states : Add a Double as a return type to the calculateTaxes method and within the method return the following expression: (self.amount * (percentage/100)).
you need to add the return type to the function (by placing -> Double at the end of the function header), as well as the return keyword so that the expression actually gets returned:
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
// add the return type and return keyword
func calculateTaxes(percentage: Double) -> Double {
return self.amount * (percentage/100)
}
}
before you had
func calculateTaxes(percentage: Double) {
self.amount * (percentage/100)
}
which, as you can see, is missing the return type as well as the return keyword. the function simply executes the line of code, it does not return anything
Colin Adler
2,225 PointsWow thanks for the fast response! Seems really dumb now that I missed that.
Stone Preston
42,016 Pointsno problem, glad I could help