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 trialNikhil Kanamarla
1,565 PointsTried to practice enums having trouble
enum shoppingList: Int { case milk = 4, case chesse = 3, case vegtables = 7 } func enumPractice (shoppingenum: shoppingList) ->Int { shoppingList.chesse.rawValue - shoppingenum.rawValue } enumPractice(shoppingList.milk) It's highlighting my last line in Xcode: "shopping list type doesn't have a member named milk"
1 Answer
anthonypaulino2
2,068 PointsOk I see what you're trying to do here. This would be the correct way to do it:
enum shoppingList: Int { case milk = 4, chesse = 3, vegtables = 7 }
func enumPractice (shoppingenum: shoppingList) ->Int { return shoppingList.chesse.rawValue - shoppingenum.rawValue }
enumPractice(shoppingList.milk)
What I first did was take out all the "case" keywords that weren't necessary. Also one of the mistakes you did was forget to type the keyword "return" because remember you are trying to return a value from it. All of people do this mistake so don't worry about it. Hope this helped!