Quiz · Enums · lesson 8 of 8
Quiz — switching on an enum
What does the program print?
enum Order {
case tea
case coffee(cups: Int)
}
func cost(_ order: Order) -> Int {
switch order {
case .tea: return 2
case .coffee(let cups) where cups > 2: return cups * 2
case .coffee(let cups): return cups * 3
}
}
print(cost(.coffee(cups: 2)), cost(.coffee(cups: 4)))