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 trialDevin LeJeune
1,480 PointsEnums and structs step 2 of 2.. I'm having trouble with the answer..
i did var travel = Expense.description = "" and i dont think i can also do var tavel = Expense.amount = 500.00
I'm kind of stuck..
struct Expense {
var description: String
var amount: Double
}
var travel = Expense.description = "Flight to Cupertino"
1 Answer
Jhoan Arango
14,575 PointsHello Devin:
From what I can see, what you are trying to do is create an instance of βExpenseβ.
struct Expense {
var description: String // String type
var amount: Double // Double type
}
// Instance
var travel = Expense(description: "Flight to Cupertino", amount: 250.00)
When creating an instance of a class or struct you have to call it by its name and its parameters. Since structs create their own initializers, you do not have to create one, just simple use its store properties as its parameters, and give them values according to their type.
Hope this helps