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!

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


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,909 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)