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

Add a method to the Expense struct that will calculate taxes based on a percentage passed to the method

I have no idea what I am doing wrong. Somebody please help me.

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

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

{
  func calculateTexas(percentage: Double) {
}
}

4 Answers

Something like:

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

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

  func calculateTaxes(percentage: Double) {
  }
}

Thank you Steve and Kevin!

Kevin Franks
Kevin Franks
12,933 Points

Check you Brackets. The close bracket for your init function is an open bracket vs. close.

I think you're pretty much there. Two things, though. One was mentioned by Kevin above; your braces aren't quite right.

Second, as just because the first part of the challenge requires nothing inside the method, is the spelling. You're calculating Taxes not Texas. ;-)

I think if you fix those two things, you'll get to the next stage. If not; just shout and we'll come and help.

Steve.

What should the brackets be instead of what I have?

Kevin Franks
Kevin Franks
12,933 Points

Change from { to } right above your function call.

In the first challenge the function does not return anything, so it should be:

func calculateTaxes(percentage: Double) () {
}

Hi Kevin,

I don't think the () are needed as omitting the return arrow and type is sufficient to show the function isn't returning anything.

I think. I'm no expert.

Steve.

Kevin Franks
Kevin Franks
12,933 Points

Kyle not Kevin though you are correct.

Sorry!! :-)