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

iOS Swift Enums and Structs Structs and their Methods Struct Methods

Nick Cottier
Nick Cottier
1,713 Points

Cant get past this challenge any help would be appreciated!

Challenge is: Then 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.swift
struct Expense {
    var description: String
    var amount: Double = 0.0
    var item: String

       init (description: String, item1: String) {
        self.description = description
        self.item = item1
        self.amount = 100.0
    }
    func calculateTaxes(percentage: Double) -> Double {
        return (self.amount * (percentage/100))
    }
}

3 Answers

Nick Cottier
Nick Cottier
1,713 Points

OK your suggestion was right just needed to modify slightly:

var item = Expense(description: "Car")

item.amount = 100

Thanks for your help :)

Max Hirsh
Max Hirsh
16,773 Points

Hm, I think if I understand the question correctly, it is asking you to create a variable called "item" that is an instance of the "Expense" struct, then set its amount to 100? It's definitely easy to mix up though because structs have internal variables too, but I don't think that was what the challenge meant to ask.

The code I would try is:

var item = Expense()

item.amount = 100

Let me know if that works!

Nick Cottier
Nick Cottier
1,713 Points

Hi thanks for the tip unfortunately that didn't work either. I have skipped this challenge for now to progress.