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
Jonathan Lee
1,565 PointsTuple Value Names
I attempted to assign price and carpet color to the tuple return values. It brings an error every time, not sure if this is because of an update in the language recently. But Xcode 7.2.1 does not allow(in my case) to use a name as an index value for tuples.
1 Answer
Digvijay Jaiswal
5,565 PointsTry the code below.
func areaOfRoom1(length l: Int, width w: Int) -> Int {
let areaRoom1 = l * w
return areaRoom1
}
func carpetAreaCostCalculator
(length length: Int, width: Int, carpetColor: String = "Tan") -> (price: Int,carpetColor: String) {
let area = areaOfRoom1(length: length, width: width)
var price: Int
switch carpetColor {
case "Tan": price = area * 1
case "White": price = area * 2
case "Blue": price = area * 4
default: price = 0
}
return (price,carpetColor)
}
let carpetCost = carpetAreaCostCalculator(length: 10 , width:20 , carpetColor: "Blue")
let carpetCost1 = carpetAreaCostCalculator(length: 10, width: 20)
print ("The cost of the \(carpetCost.1) carpet is \(carpetCost.0)")```