Course / The terminal and the language
Name the day
How to fetch and submit this lab
Once: install the tool and connect your account.
curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon loginEach lab: download it, edit the file named in the instructions, then submit.
gonomicon fetch week-1/10-04-name-the-day
cd 10-04-name-the-day
gonomicon submitGoal
Turn a package-level Day number into its name and its kind, using a switch in each function.
Example If you needed to name a month number instead, you'd write:
func MonthName() string {
switch Month {
case 1:
return "January"
case 2:
return "February"
default:
return "invalid"
}
}
Rules
- Edit
day.go. BothDayNameandDayKindhave a// TODOcomment and a return line you will change. - Write both with a
switchonDay, not anif/else ifchain. DayName:1is"Monday"through7is"Sunday". Anything else is"invalid".DayKind:1through5are"weekday".6and7are"weekend". Anything else is"invalid". List6and7together on onecaseline, the same way the lesson lists several values on one line.- Do not change
var Day intor either function's signature. Do not add imports.
What you'll practice
Writing a switch instead of a long if / else if chain, and listing several matching values on one case line.
Run it
gonomicon fetch week-1/10-04-name-the-day
cd 10-04-name-the-day
gonomicon test
gonomicon submit
Hints
- Use a switch on Day for both functions instead of an if/else-if chain, with a default case for anything invalid.
- DayKind doesn't need five separate weekday cases: list 1, 2, 3, 4, 5 together on one case line, and 6, 7 together on another.
- switch Day { case 1: return "Monday" ... case 7: return "Sunday" default: return "invalid" } and switch Day { case 1, 2, 3, 4, 5: return "weekday" case 6, 7: return "weekend" default: return "invalid" }