✦
✦
Computer Science · Coding Basics
Variables and Data Types
A program needs to remember a player’s score, name and remaining lives. It can store a value in a variable. Think of its name as a label on a box.
📦A Variable Is a Labeled Box
🏷️ Two parts to every variable:
The NAME is the label, such as score. It stays the same.
The VALUE is the current data, such as 500. A program can assign a new value.
🧰Types of data
🔤STRING
Holds text, such as names, words and messages.
💬
"Hello!" · "Maya"🔢INTEGER
Holds integer values, such as scores and lives. Integers include negative values and zero.
🎮 score =
500 · lives = 3🚦BOOLEAN
Holds true / false. Use one when a condition has two possible results.
🚪 doorLocked =
true⚡Values Can Change as the Program Runs
# make a variable and assign it a value
set score = 500
# add 100 to the current score
set score = score + 100 → now score is 600
🔑Key Terms
📦Variable A named container that stores data that can change.
🧰Data Type The kind of data a variable holds (number, text, true/false).
🔤String A data type that holds text.
🔢Integer A number with no fractional part, including negative integers, zero and positive integers.
🚦Boolean A data type with only two values: true or false.
✍️Assign To give a variable a value.
⭐
Follow the score example. The name stays the same when an assignment changes its value from 500 to 600.
✏️ Computer Science Anchor Chart · Variables & Data Storage