Module 3 · Expressions, operators, and text
Arithmetic expressions
Control evaluation order with precedence and parentheses.
What you will learn
- Read an arithmetic expression in evaluation order
- Use parentheses to make intent visible
- precedence
- Rules that determine which operator is evaluated first.
- parentheses
- Grouping marks that make part of an expression evaluate first.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
A Coin Quest score may combine coins, bonuses, and penalties. The order of those operations changes the result.
The mental model
Multiplication and division are evaluated before addition and subtraction. Parentheses create an explicit group that is evaluated first.
Use parentheses when they clarify the design, even when precedence would already produce the same value.
New words and symbols
--!strict asks Studio to check your code for type mistakes. It is an instruction for the editor and produces no Output message.
print(...) calls the built-in print function. Put the values to show inside its parentheses; separate multiple values with commas. Read the result in Studio's Output panel.
local is read as “local”: it creates a name that is available only in the current code scope.
= is read as “is assigned”: it evaluates the right side and stores that value in the name on the left.
A tiny example
--!strictlocal coins = 4local pointsPerCoin = 10local bonus = 5local score = (coins * pointsPerCoin) + bonusprint(score)Line by line
- 3
coins is the collected quantity.
- 4
pointsPerCoin names the multiplier.
- 5
bonus is added after coin points.
- 6
Parentheses make the multiplication step explicit.
- 8
The final expression value is printed.
Read the code aloud
Read one statement at a time: name the value being read, what the operation does, and where its result goes. Keep identifiers exactly as written so you can find them again in the code.
Pause at calls, conditions, and loops. Explain when the body runs before moving to the next statement; use the line notes above when a symbol is unfamiliar.
Execution trace
Begin at the first executable statement. Comments and blank lines do not run; a branch chooses which block runs, and a loop may revisit its body.
Line 3: coins is the collected quantity.
Line 4: pointsPerCoin names the multiplier.
Line 5: bonus is added after coin points.
Line 6: Parentheses make the multiplication step explicit.
Line 8: The final expression value is printed.
State before and after
Before running, identify the starting values and any existing Studio objects this example needs. List what you expect to change.
After your practice change, check this result: Your prediction and Output match the intended evaluation order.
Reading or printing a value leaves it unchanged. Look for assignments, calls that change state, and property updates to explain each change you observe.
Predict before running
Which value is stored in score?
Try it
Mark each step after you have tried it.
Common mistake
local score = coins * (pointsPerCoin + bonus)This adds the bonus to every coin's multiplier, changing the rule. Group only the operations that belong together.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Expressions produce values.
- Precedence affects operation order.
- Parentheses make important groups explicit.
Next: Next, you will update stored values with compact compound operators.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.