lesson

A variable stores a value that can change

1 · Learn

A variable gives a stored value a name. In a game, score might begin at 0 and change when a correct action occurs. Setting score to 1 replaces the value; changing score by 1 adds to its current value.

Choose names that explain the value's job. A display of the score is not the same as the stored variable, and a variable in memory is not automatically saved after the program closes.

Set: replaceChange: add differenceDisplay: showSave: separate action
Key words and supplied examples.

2 · Worked example

Starting at score 0, changing by 1 twice gives 2. Setting score to 1 twice leaves 1. The commands are not interchangeable.

3 · Your turn

Score starts at 4. It changes by 3, then is set to 2. What is its final value?

Check your answer

2. The final set command replaces the earlier value of 7.

4 · Apply your learning

Trace and run a short approved block program using both set and change commands; compare your predictions.

Adult guidance and safety

Use a school-approved offline or supervised tool and fictional data. Keep work private, respect media permissions and check accessibility. Paper traces support understanding but do not replace running, saving and testing a real project. Do not enter passwords, addresses or other personal details into exercises.

Open your writing and drawing pad

Write, draw or show your working. Use a mouse, pen or finger. This pad is not a submitted answer.

Not saved to your account. Download your drawing as PNG and your typed notes as TXT before leaving or refreshing. They are separate files. Do not enter private information.

Open a picture saved on this device to draw on it again. Opening replaces the drawing, but Undo can restore it. PNG only, up to 4 MB and 4096 × 4096 pixels. The picture stays in this browser; it is not uploaded. Paper lines in a saved picture become part of that picture.

Drawing is unavailable. Use the typed working area below.

Your pad is empty.

Open a UTF-8 TXT file from this device, up to 40 KB and 10,000 characters. It stays in this browser. Opening can be undone until you type again. Downloads keep a new copy; they do not change the file you opened.

Typed notes are not submitted answers.

Check a calculation · Year 5 onward

Use this only when your teacher or adult allows a calculator for the task. Show your thinking first. It does not replace mental or written arithmetic and does not mark your lesson answer.

Practice this lesson

Lesson resources

Browse the available practice activities and worksheets for this lesson.

Open course resources

Your progress

Ready to continue?