25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →

Interactive Go · Lesson

Constants & iota

Some values should never change mid-quest — the size of your backpack, the name of your guild. For these, Go gives you const:

const maxInventory = 10

When you need a run of related constants, iota numbers them for you, starting at 0 and incrementing for each line:

const (
    Bronze = iota // 0
    Silver        // 1
    Gold          // 2
)

Your Quest

Define a constant block using iota for three ranks — Novice, Squire, and Knight — so that Knight has the value 2.

Expected output:

Max inventory: 10
Knight rank value: 2

Hint

Open a const ( ... ) block, set Novice = iota, then list Squire and Knight on their own lines — they pick up 1 and 2 automatically.

Additional Scrolls of Wisdom