25% off

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

Get started →

Interactive Go · Lesson

Functions Revisited

Functions are how you package up a spell to cast again and again. You’ve called them already — now let’s wield them properly. A Go function declares its parameters and its return type(s):

func heal(amount int) int {
    return amount * 2
}

A real strength of Go is multiple return values — perfect for returning a result and a status together:

func divide(a, b int) (int, bool) {
    if b == 0 {
        return 0, false
    }
    return a / b, true
}
result, ok := divide(10, 2)

You can even name the return values for clarity (func attack() (damage int, crit bool)), though we’ll keep it simple here.

Your Quest

Complete attack so it returns two values: the damage (strength * 2) and a boolean that is true when strength is greater than 10.

Expected output:

24 true

Hint

return strength * 2, strength > 10 — the comparison strength > 10 is itself a bool.

Additional Scrolls of Wisdom