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 trial
kaitlanlang
3,042 PointsAdd a method to the Expense struct that will calculate taxes based on a percentage and add it to the stored property am
this is a beginners course Amit, you have many smart people doing it. but It is very getting tiring watching material over and over and only having real vague ideas how to proceed.Applying a new concept is only useful when the concept is clear after video. Referencing the apple swift book is a great idea to solidify a taught concept, but having to go there to learn it completely because video was not clear at all is poor form. Its not just the concept either, sometimes you may understand a concept but question presentation leaves you scratch your head what is being asked. Anyway rant over, question with my working I have no idea about
Add a method to the Expense struct that will calculate taxes based on a percentage and add it to the stored property amount. In this task, add a method named calculateTaxes which accepts a parameter named 'percentage' of type double and does not return anything. (In the next task we will add the calculations to the method).
below I am returning nothing as requested by question and it accepts one parameter percentage. please explain the err of my ways comprehensively amit.
struct Expense {
var description: String
var amount: Double = 0.0
init (description: String) {
self.description = description
}
func calculateTaxes(percentage: Double) -> {
return
}
}
2 Answers
kaitlanlang
3,042 PointsHi Michael, thanks for the reply. I went and read the apple swift book on functions and found a spot in book with 'no' return types, I entered the to follow code and it accepted it as correct. Since the question only wanted us to do part of task more to be done in other questions, essentially my understanding of what was being asked was to leave a placeholder function to be worked on later. So the following felt counter intuitive. My light bulb moment was realising that as nothing is being returned this symbol -> is not needed.
struct Expense {
var description: String
var amount: Double = 0.0
init (description: String) {
self.description = description
}
func calculateTaxes(percentage: Double) {
}
// add the calculateTaxes method here
// it should accept only one parameter named 'percentage' of type Double
}
Michael Cobb
2,166 PointsAwesome job doing the research! I didn't necessarily understand it as well as you explained.
Thanks!
kaitlanlang
3,042 PointsThanks Michael, your comment has made my day :)
Michael Cobb
2,166 PointsMichael Cobb
2,166 PointsThis one was pretty difficult!
Give this a try...