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 Functions in Swift Adding Power to Functions Default Values

Stephen Flynn
Stephen Flynn
713 Points

I'm getting an error at this point.

I get an error at all case values:

//Default Values

func carpetCostHaving(length: Int, width: Int, carpetColor color: String = "tan") -> Int { // Gray carpet - $1/sq ft // Tan carpet - $2/sq ft // Deep Blue carpet - $4/sq ft

let areaOfRoom = (length: length, width: width)

var price = 0

switch color {
    case "gray": price = areaOfRoom * 1
    case "tan": price = areaOfRoom * 2
    case "blue": price = areaOfRoom * 4
default: price = 0
}

return price

}

carpetCostHaving(length: 10, width: 50, carpetColor: "tan")

1 Answer

You are suppose to be calling the 'area' function. Otherwise your cases are trying to multiply a tuple times the price per sq ft.

let areaOfRoom = area(length: length, width: width)
func area(length: Int, width: Int) -> Int{
    let areaOfRoom = length * width
    return areaOfRoom
}