Hello! I am working with enums in the Playground now. I have an exercise: _Comment out the final return statement to see an error. Uncomment it again, and try to change the value passed in to cookLunch so that the final else statement is called.
(Hint: How would you get an enum value that didn’t match anything in the if statement?)_
And I have this code:
enum LunchChoice {
case pasta, burger, soup
}
func cookLunch(choice: LunchChoice) -> String {
if choice == .pasta {
return "🍝"
} else if choice == .burger {
return "🍔"
} else if choice == .soup {
return "🍲"
} else {
return "Umm... how did we get here?"
}
}
cookLunch(.pizza)
I have tried to put a string value into the function, but then it was complaining about if statements with enums. Then I've tried to put a string value after an enum value, but it was complaining that by calling a function my first parameter with an enum wasn't mentioned. So I don't understand what to do
First, this cannot compile. Need add argument label:
cookLunch(choice: .pizza)
But this will fail as well of course as pizza is not in enum…
So, add pizza to the enum and comment out as instructed.
See complete details here: https://stackoverflow.com/questions/46140581/enumeration-behaviour-understanding-intro-to-app-development-with-swift-lesso