Course outline
Course / The terminal and the language

Choose the right box shape

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/08-03-pick-the-right-type
cd 08-03-pick-the-right-type
gonomicon submit

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

Goal Fill in five functions so each returns the exact value described, using the type that fits it.

Example If a function were meant to return a weight of 2.5 kilograms, you would write:

func Weight() float64 {
	var weight float64 = 2.5
	return weight
}

The variable's type matches the shape of the value, and the return line hands it back.

Rules

  • Edit types.go. Each function has a // TODO comment and a return line you will change.
  • Price should hold 19.99 in a float64.
  • Quantity should hold 12 in an int.
  • Shipped should hold true in a bool.
  • Code should hold "GO-7" in a string.
  • Stock should hold 250 in a uint.
  • The function names and what they return are fixed. Do not change the lines that start each function.
  • Do not add imports. You will not need any.

What you'll practice Picking int, uint, float64, bool, and string for the value that fits each one.

Run it

gonomicon fetch week-1/08-03-pick-the-right-type
cd 08-03-pick-the-right-type
gonomicon test
gonomicon submit

Hints

  1. Each function already tells you the exact value to return. Your job is to put that value in a variable of the matching type, then return it.
  2. Price needs a float64 holding 19.99. Stock needs a uint holding 250, which works because 250 is never negative. The rest follow the same shape.
  3. var price float64 = 19.99 then return price. The same pattern works for Quantity, Shipped, Code, and Stock — just swap the type and value each time.

Something wrong with this lesson? Report a problem