Printing Literals
Part of the Fundamentals section of Coddy's Lua journey — lesson 26 of 90.
let's revisit the print() function to focus on outputting literal values directly. Literal values are fixed pieces of data that you write directly in your code, like specific numbers or text strings.
You can print numbers directly by passing them to the print() function:
print(100) -- Prints: 100
print(42.5) -- Prints: 42.5Similarly, you can print string literals by enclosing text in quotes:
print("Welcome!") -- Prints: Welcome!
print('Game Over') -- Prints: Game OverChallenge
EasyDisplay a game's welcome message and starting score using literal values. Print the string "Welcome to Adventure Quest!" on the first line, then print the number 0 on the second line to show the player's starting score.
Cheat sheet
You can print literal values directly using the print() function.
Print numbers:
print(100) -- Prints: 100
print(42.5) -- Prints: 42.5Print strings using quotes:
print("Welcome!") -- Prints: Welcome!
print('Game Over') -- Prints: Game OverTry it yourself
-- TODO: Write your code hereThis lesson includes a short quiz. Start the lesson to answer it and track your progress.
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