Assigning values to variables

We’ll use assignment expressions like x = 5 and take keyboard input to fill RAM boxes.

Watch the values travel into memory!

Friendly student character

1) Assignment Expressions

When we write x = 5, we’re saying “put 5 into the box named x.” If we write y = x + 2, the CPU first looks up x, adds 2, then stores the result in y.

RAM — our boxes

x
number
y
number
name
text
5
7
Alex

You’ll see x fill first, then the CPU calculates y, then name is stored.

Try your own expression

Choose x or y. Use a number or another variable in your expression.

Picture it

Character near laptop

The CPU reads the right side, does the math, and stores the answer in the left-side box.

2) Keyboard Input → Variable

Typing on a keyboard gives characters. The computer turns them into codes (numbers) and stores them in RAM.

Type your name

playerName
text
age
number
isReady
true/false
You
Keyboard
CPU
RAM

Enter your age

Smiling character

Numbers from the keyboard go through the CPU then into RAM too.

Ready switch

Happy kids

true and false are like an On/Off switch.