← Starting out

Text or number?

The same keys can make text or a number, and the computer does different things with each. Numbers can be added: 12 and 3 make 15. Text can only be joined: 12 and 3 make 123. So programs store things you'll do maths with as numbers, and things like names and phone numbers as text.

12 and 3 make 15. But a computer can also turn 12 and 3 into 123. How does it know which to do?

When you type 12, the computer has to decide: is it the number twelve, or the two characters 1 and 2?

How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

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?

TryTry it on the board and compare the result with your prediction.

Try: type 12 as text

Was your guess right?

Try it yourselfYour edits are saved in this browser.

Type 12 in the box. How many numbers does the computer store for it?

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

Worked example: same keys, different jobs

Worked exampleBefore each step, say what you think comes next.
  1. 12+3=1512 + 3 = 15Stored as numbers: the computer adds them.

Now: which can be added?

Which can the computer add up to make a total?

Sam joins two text boxes. Click the line where it first goes wrong.

Why is a phone number like 0412 345 678 stored as text?

ModifyChange the problem on purpose and see what happens.

Vary: what happens?

5 and 4 are stored as numbers. The computer adds them. What does it show?

Now 5 and 4 are stored as text. The computer joins them. What does it show?

cat and fish are stored as text. The computer joins them. What does it show?

PractiseA few on your own, to check you have it.

Which type?

A game keeps your score and adds 10 every time you win. How should it store the score?

A class list sorts names from A to Z. What type are the names?

Review: A is 65. What number is the letter F?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

Design a sign-up form

Then: think of a box on a real form. Would a number or text be safer?

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
Member's name
Parent's phone number
Postcode
Points earned this term
Year level

Now you can
Next lesson3. On or offInside a computer are tiny switches that can only be on or off. On is written 1 and off is 0. One switch makes 2 patterns, two make 4, three make 8: every switch you add doubles the patterns. Patterns of switches are how a computer stores numbers.
For teachers

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). About 35 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

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.

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

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.

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()).

What each step is for