Recap - Simple Logic
Part of the Fundamentals section of Coddy's Lua journey — lesson 25 of 90.
Challenge
EasyDetermine if a character can perform a special attack by combining multiple logical conditions. Create a variable called hasHighEnergy and assign it the value true. Create a variable called hasFullHealth and assign it the value false. Create a variable called hasSpecialPowerUp and assign it the value true. The character can perform the special attack if they have high energy AND either full health OR a special power-up. Use logical operators to create a variable called canPerformSpecialAttack that stores the result of this complex condition. Print the boolean result.
Try it yourself
-- Create the required variables
local hasHighEnergy = true
local hasFullHealth = false
local hasSpecialPowerUp = true
-- TODO: Write your code here to determine if the character can perform a special attack
-- Use logical operators to combine the conditions
-- Print the result
print(canPerformSpecialAttack)All 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