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

becky hayes
becky hayes
2,226 Points

Not sure why this isnt compiling..

The challenge is: Add a Double as a return type... and within the method return the following expression (self.amount * (percentage/100))

I feel like i'm very close but there's obviously something i'm getting wrong!

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))
   }
}

3 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,631 Points

Hey Becky,

Your code is correct, but there seems to be an extra backslash in your return statement (right before the opening parenthesis). Just delete that and it will pass.

Keep Coding! :)

Thomas McCracken
Thomas McCracken
13,591 Points

Also, when you divide by 100 make sure it is 100.0 as this is a Double value and not an Int. Not sure if that will make a difference but you want to be sure to return a Double value. Good luck!

Steven Deutsch
Steven Deutsch
21,046 Points

In Swift, if you divide a Double by an Integer literal, the compiler will infer the result to be of type Double.

Thomas McCracken
Thomas McCracken
13,591 Points

Oh, good to know. You never know how the compilers will interpret it in different languages. thanks for the info.