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

Josh Smith
Josh Smith
1,049 Points

I don't think the video training in any way has enabled this challenge to be tackled easily...

I've had a tremendously difficult time trying to complete this challenge have been in and out of the forum on all 4 steps in this 4 step test. Can someone please help me stumble through this last piece :(

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

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

    // add the calculateTaxes method here


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

var item = Expense(description: "My description")

2 Answers

Step 1:

func calculateTaxes(percentage: Double) {

}

Step 2"

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

Step 3:

var item = Expense(description: "MacBook Pro (really cheap one)")
item.amount = 100

Step 4:

var taxes = item.calculateTaxes(7.5)

Perhaps you forgot to assign 100 to the amount property?

Josh Smith
Josh Smith
1,049 Points

Thanks Dom, my biggest challenge is understanding the questions properly and then trying not to OVERCOMPLICATE the answer... So I spent a long yesterday NOT actually changing the amount = 0.0 to 100 because it seemed too simple.

Oh well... learning slowly!

Ricardo Gonzalez
Ricardo Gonzalez
2,286 Points

Is that the last step for the challenge or is there more steps?

Josh Smith
Josh Smith
1,049 Points

yeah that was the last dude