Recap - Treasure Chest
Part of the Fundamentals section of Coddy's Lua journey — lesson 43 of 90.
Challenge
EasyCreate 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 messageAll lessons in Fundamentals
4Operators 2 Relational & Logic
Equality OperatorsRelational OperatorsThe 'and' OperatorThe 'or' OperatorThe 'not' OperatorShort-Circuit EvaluationTruthy and Falsy ValuesRecap - Simple Logic7Basic Conditional Logic
The if-then StatementThe if-then-else StatementThe elseif StatementRecap - Treasure Chest2Variables and Data Types
What is a Variable?NumbersStringsBooleansThe Value 'nil'The type() FunctionNaming ConventionsRecap - Character Profile5Basic Output
Printing LiteralsPrinting VariablesPrinting Multiple ValuesCombining Strings & VariablesThe tostring() FunctionInputCastRecap - Status ReportRecap - Till 1208String Manipulation Basics
string.len()string.upper & string.lowerstring.sub()string.rep()string.find()Recap - Format Username3Operators 1 Arithmetic & Conc
Arithmetic OperatorsModulo OperatorExponentiation OperatorString ConcatenationOperator PrecedenceRecap - Simple Calculations6Project: Character Stats Disp
Welcome MessageDeclare Character Stats9Functions Basics
Declaring a FunctionCalling a FunctionFunctions with ParametersFunctions with Multiple ParamsThe 'return' StatementRecap - Area Calculator