Menu
Coddy logo textTech

Recap - Treasure Chest

Part of the Fundamentals section of Coddy's Lua journey — lesson 43 of 90.

challenge icon

Challenge

Easy

Create a treasure chest reward system that determines what a player receives based on the type of key they possess. Declare a variable called keyType and assign it the value "silver key". Use a complete if-elseif-else structure to check the key type and award the appropriate treasure:

  • If the player has a "gold key", print "You found gold!"
  • If the player has a "silver key", print "You found silver!"
  • For any other key type (or no key), print “The chest is empty.”

Try it yourself

-- Declare the keyType variable
local keyType = "silver key"

-- TODO: Write your code here
-- Use if-elseif-else structure to check keyType and print the appropriate message

All lessons in Fundamentals