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.


Kami Wang
Kami Wang
5,643 Points

Returning Complex Values-- I wrote exactly the same code which in the video, but there are three errors. Why?

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 = calcalateArea(length, width: width)

    var price: Int

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

let result = carpetCostCalculator(length: 10, width: 20)   [Error:Ambiguous use of 'carpetCostCalculator(length:width:carpetColor:)'

result.price   [Error:Value of type 'Int' has no member 'price']
result.carpetColor   [Error:Value of type 'Int' has no member 'carpetColor']

1 Answer

Michael Hulet
Michael Hulet
47,842 Points

Somewhere, you have carpetCostCalculator(length:width:carpetColor:) defined more than once, and the multiple different implementations are defined to accept and/or return different types, and Swift doesn't know which one to use. Solve that error by specifying what you want where there is ambiguity, and your code should work (in a Playground)