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 trialCharles Harpke
33,986 PointsCreate a variable named travel and assign it an instance of the Expense struct with the following values for each stored
here is my code:
``swift struct Expense { var description: String = "description" var amount: Double = 0.00
init(description : String) {
self.description = description
}
var travel = Expense(description: "Flight to Cupertino", amount: 500.00)
} `` and my error: error: swift_lint.swift:10:25: error: extra argument 'amount' in call var travel = Expense(description: "Flight to Cupertino", amount: 500.00)
struct Expense {
var description: String = "description"
var amount: Double = 0.00
init(description : String) {
self.description = description
}
var travel = Expense(description: "Flight to Cupertino", amount: 500.00)
}
1 Answer
Greg Kaleka
39,021 PointsHi Charles!
Your init method signature only has one parameter. You need to either 1. add another parameter to your method signature, or 2. set the amount property outside of calling init. Also, on the property/properties that are being set in init, there's no need to set a default value. I've made that change in the options below.
Option 1:
struct Expense {
var description: String
var amount: Double
init(description : String, amount: Double) {
self.description = description
self.amount = amount
}
var travel = Expense(description: "Flight to Cupertino", amount: 500.00)
}
Option 2:
struct Expense {
var description: String
var amount: Double = 0.00
init(description : String) {
self.description = description
}
var travel = Expense(description: "Flight to Cupertino")
travel.amount = 500.00
}