C23 · Topic 3.4 · 40 minutes · AAP-2.D
Strings and text values
By the end you can:
- Distinguish text digits from numerical values.
- Trace exact concatenation.
- Account for spaces as characters.
Before this lesson: topics 3.1.
- String
- A sequence of characters used as text.
- Concatenation
- Joining text values in order without adding implied separators.
Understand
A string represents text even when its characters are digits. Joining “2” and “7” as text produces “27”, not the sum 9. Interpret an operation according to its contract and the kind of values supplied. A room code may need leading zeros preserved, unlike a numerical count used in arithmetic.
Concatenation joins the characters exactly in order. It does not insert a space unless one argument contains a space or the algorithm adds one. When explaining a text output, show quoted strings or otherwise make spaces visible so an apparently minor difference is testable.
Worked example
concat joins its two arguments exactly. Build a label from “Room ”,“2” and “7”.
label ← concat("Room ", concat("2", "7"))- The inner concatenation gives “27”.
- The first argument includes one trailing space.
- The full result is “Room 27”, not “Room 9”.
Explore each concept
Choose a concept, change its inputs and follow the explanation. Each example models the stated rule or scenario; completing it is practice rather than evidence of mastery.
- Text digits versus numbers
- Concatenation and length
- Literal spaces and leading zeros
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- Left text (max 30 characters)007Waiting
- Right text (max 30 characters)2Waiting
- SeparatornoneWaiting
Ready to explore: Join exact strings and preserve spaces
Why: Change an input, predict the first effect, then advance one step.
Try this: Change one input or choose another listed case. Predict the effect, reset and compare the states and governing rule.
Step through and experiment
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- Input 1PLANETWaiting
- Input 22Waiting
- Input 33Waiting
Ready to experiment
Why: Predict the first change, then advance one step.
Try this: Try count 0, a count beyond the end, and start one past the last character.
Check a misconception
Claim: Text containing digits is automatically added numerically.
A text operation acts on characters unless a conversion or different contract is explicitly supplied.
Guided practice
Predict concat("Left:"," seats")and explain the space.
Work with a partner. Make a prediction, compare your reasoning, then identify the rule that supports your answer.
Independent transfer
A code “007” is converted to a number and then displayed. What information may be lost?
Exit check
Why must the order of concatenation be preserved?
Write your reasoning before comparing with a classmate. If your teacher assigned this task, submit it through My classes to save your work and receive feedback.
Check yourself
Your practice so far
Check an answer to see its rationale.