Course outline
Course / The terminal and the language

What to wear

Lab

How to fetch and submit this lab

Once: install the tool and connect your account.

curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon login

Each 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 submit

Go installed? gonomicon test runs the visible test on your computer first. Submitting also runs hidden checks on our server.

Goal 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. Advice has a // TODO comment and a return line you will change.
  • Return "hot" when Temp is above 30.
  • Return "mild" when Temp is above 15 (but not above 30).
  • Return "cold" otherwise, including negative temperatures.
  • Read the package-level Temp variable; do not add a parameter to Advice.
  • Mind the borders: 30 itself is "mild", not "hot", and 15 itself is "cold", not "mild".
  • Do not change var Temp int or the Advice function 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

  1. Temp is a package-level variable the tests change before calling Advice(). Read it, don't take it as a parameter.
  2. 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.
  3. if Temp > 30 { return "hot" } else if Temp > 15 { return "mild" } else { return "cold" }

Something wrong with this lesson? Report a problem