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

iOS

Matthew Foster
Matthew Foster
7,442 Points

Why even bother typing out the rest of the enum options instead of just using default in the switch statement?

switch day { case Day.saturday, Day.sunday: return "Weekend" default: return "Weekday" }

instead of

switch day { case Day.saturday, Day.sunday: return "Weekend" case Day.monday, Day.tuesday, Day.wednesday, Day.thursday, Day.friday: return "Weekday" }

Seems like the latter is a lot of wasted work.

(This is related to this course https://teamtreehouse.com/library/modeling-finite-data not sure why it didn't link to it like the other questions asked...)

1 Answer

Sarah Hurtgen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sarah Hurtgen
Treehouse Project Reviewer

Since the video you linked is one of the very first to introduce enums, my guess is that he was just trying to help give some initial practice of accessing the enum values before expounding on some of different ways you can write them. In the next video Getting rid of strings, he touches on "default" and refactors his code to look more like what you wrote in your first example!