Course / The terminal and the language
What to wear
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-02-temperature-advice
cd 10-02-temperature-advice
gonomicon submitGoal
Return "hot", "mild", or "cold" based on a package-level Temp variable, using an if / else if / else chain.
Example If you needed speed advice instead, you'd write:
func SpeedAdvice() string {
if Speed > 100 {
return "fast"
} else if Speed > 50 {
return "moderate"
} else {
return "slow"
}
}
Rules
- Edit
advice.go.Advicehas a// TODOcomment and a return line you will change. - Return
"hot"whenTempis above30. - Return
"mild"whenTempis above15(but not above30). - Return
"cold"otherwise, including negative temperatures. - Read the package-level
Tempvariable; do not add a parameter toAdvice. - Mind the borders:
30itself is"mild", not"hot", and15itself is"cold", not"mild". - Do not change
var Temp intor theAdvicefunction signature. Do not add imports.
What you'll practice
Writing an if / else if / else chain, and placing > correctly so each border lands on the right side.
Run it
gonomicon fetch week-1/10-02-temperature-advice
cd 10-02-temperature-advice
gonomicon test
gonomicon submit
Hints
- Temp is a package-level variable the tests change before calling Advice(). Read it, don't take it as a parameter.
- Three outcomes need two questions: first check if Temp is above 30, then else if it's above 15, then a plain else for everything left over.
- if Temp > 30 { return "hot" } else if Temp > 15 { return "mild" } else { return "cold" }