← Teacher guide

Text or number?

Students see that 12 typed as text is two characters with their own codes, compare adding numbers with joining text, and choose number or text for each box on a sign-up form (AC9TDI6K03 node 2).

Starting out · Numbers and switches · about 35 minutes · Open the student lesson

Classroom resources

Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Try 6 min · Worked example 10 min · Vary 6 min · Practise and Make 13 min

Before class

Do the Try board yourself: type 12, then 123.

The one idea: the type of data (number or text) decides what the computer can do with it. Numbers add; text joins.

Simplification: in programs this is "string" and "integer"; spreadsheets show it as a number lined up on the right and text on the left. Neither word is needed here.

Year 7–8 catch-up: Text as numbers (8K03 n2) assumes students know a digit in text is a character; this lesson is that idea.

Running the lesson

  1. Predict: students who chose 15 added; ask what joining two words does.
  2. Try: ask why 12 needs two numbers here but would need one as a number.
  3. Worked example: ask what goes wrong if a phone number loses its 0.
  4. Make: let pairs argue about year level; adding 1 next year is the deciding job.

In class

On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.

The hard part (on purpose)

Thinking text that looks like a number is a number. Have them type 12 on the board and count the codes.

When students get stuck

What you will seeA question to askThe fix
A student says the computer adds text that looks like numbers (Sam's mistake).What does joining cat and fish make? Now join 12 and 3.Text joins; only numbers add.
A student says a phone number is a number.Would you ever add two phone numbers?No maths, and the leading 0 must stay: text.

Answers to the checks

  1. join or add?: A form has two text boxes. Ana types 12 in one and 3 in the other. The form joins the two pieces of text together. What does it show?
    123. Joining text puts one piece after the other. Only numbers get added.
  2. Try: type 12 as text: Type 12 in the box. How many numbers does the computer store for it?

    Two: 49 for the character 1 and 50 for the character 2. As text, 12 is two characters in a row, like the letters in a word.
  3. 12 and 3, two ways: Which can the computer add up to make a total?
    12 stored as a number
    Numbers can be added, taken away and sorted by size. Text can be joined and sorted A to Z.
  4. Find the mistake: Sam joins two text boxes. Click the line where it first goes wrong.
    line 3
    Line 3: text is stored as codes, but the computer doesn't add text. It joins it, so the box shows 123.
  5. Phone numbers: Why is a phone number like 0412 345 678 stored as text?
    You never add them, and the 0 at the front must stay
    As a number, 0412 would lose its 0 and become 412. As text, every character stays.
  6. Add: 5 and 4 are stored as numbers. The computer adds them. What does it show?
    9
    As numbers they add: 5 + 4 = 9.
  7. Join: Now 5 and 4 are stored as text. The computer joins them. What does it show?
    54
    As text they join: 5 then 4, which is 54.
  8. Join words: cat and fish are stored as text. The computer joins them. What does it show?
    catfish
    Text joins: catfish.
  9. Score: A game keeps your score and adds 10 every time you win. How should it store the score?
    As a number
    The game does maths with it, so it's a number.
  10. Names: A class list sorts names from A to Z. What type are the names?
    Text
    Names are text: sorted A to Z by their letter codes, never added.
  11. Review: codes: Review: A is 65. What number is the letter F?
    70
    Count on five from 65.
  12. design a sign-up form: You're making the sign-up form for the Coding Club. For each box, choose how to store it.
    How many robots each member built → Number: we'll do maths with it; Member's name → Text: we won't; Parent's phone number → Text: we won't; Postcode → Text: we won't; Points earned this term → Number: we'll do maths with it; Year level → Number: we'll do maths with it
    Ask: will the program do maths with it? Then it's a number. If not, text keeps every character just as it was typed.

Stretch and support

Stretch: A spreadsheet shows 0412 as 412. What happened, and how could you stop it?

Support: A card: Number: add, take away, compare sizes. Text: join, sort A to Z, keep every character.

Exit ticket

A and B are 5 and 6. As numbers, what do they make together? As text?

11 (added); 56 (joined).

What each step is for

Where it leads

Next: On or off (how switches store numbers).

Year 7–8: Everything is numbers; in Code, Python console › Text into numbers (int()).