25% off

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

Get started โ†’

Interactive Go ยท Lesson

Quest: The Dungeon Crawl

Time to descend into the dungeon, adventurer. You’ll need loops and conditionals working together โ€” a for loop to visit each room, and an if inside to decide what awaits.

The remainder operator % is handy here: n % 2 == 0 is true when n is even.

if step%2 == 0 {
    fmt.Println("even step")
}

Your Quest

Loop from room 1 to rooms (5). For each room, print Room N: trap! if the room number is even, otherwise Room N: safe. (using the real number in place of N).

Expected output:

Room 1: safe.
Room 2: trap!
Room 3: safe.
Room 4: trap!
Room 5: safe.

Hint

Loop with for i := 1; i <= rooms; i++, then inside use if i%2 == 0 { ... } else { ... } with fmt.Printf("Room %d: ...\n", i).

Additional Scrolls of Wisdom