Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Enums and Structs Structs and their Methods Struct Methods

what value should i give to var taxes?

please some one help!!

struct.swift
struct Expense {
    var description: String
    var amount: Double = 0.0

    init (description: String) {
        self.description = description
    }


    func calculateTaxes(percentage: Double) -> Double{
      return self.amount * (percentage/100.00)

    }


}

var item = Expense(description: "hello")
item.amount = 7.5
item.calculateTaxes(percentage: Double)
var taxes = calculateTaxes(percentage)

1 Answer

cm21
cm21
150,854 Points

Hi David,

Challenge 3 asks us to set item.amount to 100, so we'll do that.

As for Challenge 4, we'll pass in 7.5 as an argument to the calculateTaxes method (this 7.5 will be the tax percentage, as you've defined in the calculateTaxes method's header.) We need to specify our variable of item when calling this method (which is an instance of Expense), because item's amount property holds the value that we want to calculate taxes on.

var item = Expense(description: "hello")
item.amount = 100
var taxes = item.calculateTaxes(7.5)

Hope this helps!