25% off

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

Get started โ†’

Interactive Go ยท Lesson

Quest: The Locked Chest

A locked chest sits before you. This quest brings together Module 6: an interface (Lock) implemented by a type (Chest), and the error it returns when the wrong key is used.

Your Quest

Call l.Open("silver"). If it returns an error, print it; otherwise print The chest opens!. Since the chest only opens for "gold", you should see:

the chest stays shut

Hint

err := l.Open("silver"), then if err != nil { fmt.Println(err) } else { fmt.Println("The chest opens!") }.

Additional Scrolls of Wisdom