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

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,860 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.