Course / The terminal and the language
Choose the right box shape
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/08-03-pick-the-right-type
cd 08-03-pick-the-right-type
gonomicon submitGoal 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// TODOcomment and a return line you will change. Priceshould hold19.99in afloat64.Quantityshould hold12in anint.Shippedshould holdtruein abool.Codeshould hold"GO-7"in astring.Stockshould hold250in auint.- 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
- 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.
- 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.
- 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.