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

Brandon Mahoney
PRO
Brandon Mahoney
iOS Development with Swift Techdegree Graduate 29,873 Points

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
}