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 trialEdwin Mhoy Silva Rifa
2,631 PointsCanΒ΄t assign item to an instance??
Create a variable named item and assign it an instance of Expense (remember to use the initializer with the description parameter. Enter any description you like). On the next line assign the amount property a value of 100.
struct Expense {
var description: String
var amount: Double = 0.0
var item = Expense
init (description: "Kage er godt"), item: String, amount: 100 {
self.description = description
}
func calculateTaxes(percentage: Double) -> Double{
return (self.amount * (percentage/100) )
}
}
var item = Expense
Renato Nobre
5,805 PointsRenato Nobre
5,805 PointsHi Edwin, I identified the error in the code and what you need to do. So, first, you don't need to create the "var item = Expense" inside the struct, try wiping that line out. Next, looks like something is wrong with your init method, we don't need to specify a description there, neither the item and the amount, it should look like this:
Now on your last line of code "var item = Expense" you need to put parentheses and now specify the description inside the parentheses, like this:
var item = Expense(description: "You should enter a description here")
And than to call the amount property you should use dot notation for your var item and assign it to 100:
item.amount = 100
Hope you got it all, here is my full code in case you get lost:
Obs: Task 4 not included, I don't want to spoil!
Fell free to contact me on my facebook page on twitter if you have any further questions, just check on my profile!
And I highly recommend you to read some swift Documentation on methods and enums: Swift Methods, Swift Enums
You are doing a nice Job, keep up! Good Luck