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

I don't understand why this will to work!

I don't understand why this will to work i did the same exact thing as Pasan

//: Default values

func carpetCostCalculator(length length: Int, width: Int, carpetColor: String = "tan") -> (price: Int, carpetColor: String) {
    // Gray carpet - $1/sq ft
    // Tan Carpet - $2/sq ft
    // Deep Blue Carpet - $4/sq ft
    let area = calculateArea(length, width: width)
    var price:Int

    switch carpetColor {
        case "gray":price = area * 1
        case "tan": price = area * 2
        case "blue": price = area * 4
    default: price = 0
    }
    return (price, carpetColor)

}

let result = carpetCostCalculator(length: 10, width: 20)
result.price
result.carpetColor

on my computer it pops an error on the last three lines of code saying "Invalid redecoration of "result" ", "Value of type "Int" has no member "price" ", "Value of type "Int" has no member "carpetColor" ". this three quotes go in order of the code. can someone help me please because it is the same thing as Pasan and it is giving me errors.

That is odd that part of it at the top doesn't show up in code. But still could someone help me with reading the top and bottom because there is nothing wrong with the middle I domino think?

1 Answer

One thing I notice so far in your first function:

r(length length: Int,

You have length twice and a space in between...

But that is what Pasan did its so you can name the parameter or see the name in the parameter because it disappears on the first one. Right?

Yes, that is correct, that will not throw a compiler error.