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

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