💡 Quick Study Guide
- ✨ Variables in Scratch are like digital containers used to store data that can change during a project's execution.
- 🏷️ You create a variable using the 'Make a Variable' button in the 'Variables' block palette. You can choose if it's 'For all sprites' (global) or 'For this sprite only' (local).
- 🔢 The primary block for assigning an initial or specific value to a variable is the 'set [variable] to [value]' block.
- ➕ To modify a variable's value by adding or subtracting a certain amount, you use the 'change [variable] by [amount]' block.
- ❓ Variables can store different types of data, including numbers (e.g., score, lives), text (e.g., player name), or even boolean (true/false) values.
- 🚀 It's a best practice to initialize variables (assign them a starting value) at the beginning of your script, often when the green flag is clicked, to ensure predictable behavior.
- ⚙️ Examples of values you can assign include direct numbers (e.g., 0, 100), text strings (e.g., "Hello"), results of mathematical operations (e.g., $5 \times 2$), or sensor values (e.g., 'loudness').
🧠 Practice Quiz
- Which block is primarily used to give a variable a specific, new value, overwriting any previous value?
A. add [value] to [variable]
B. change [variable] by [value]
C. set [variable] to [value]
D. increase [variable] by [value] - If you want to create a variable that can be accessed and changed by any sprite in your Scratch project, what option should you select when making the variable?
A. For this sprite only
B. Global variable
C. For all sprites
D. Shared variable - What value would the variable 'score' have after these blocks are executed?
set [score] to [0]
change [score] by [5]
set [score] to [10]
A. 0
B. 5
C. 10
D. 15 - Which of the following is NOT a common type of data that a variable in Scratch can store?
A. Numbers
B. Text strings
C. Images
D. Boolean (true/false) values - You are creating a game and want to reset the player's 'lives' variable to 3 every time the green flag is clicked. Which block sequence is most appropriate?
A. when green flag clicked
change [lives] by [3]
B. when green flag clicked
set [lives] to [3]
C. when green flag clicked
add [3] to [lives]
D. when green flag clicked
if [lives = 0] then set [lives] to [3] - If a variable named 'message' currently holds the value "Hello" and you execute the block
set [message] to "World", what will be the new value of 'message'?
A. "HelloWorld"
B. "Hello World"
C. "World"
D. "Hello" - What is the primary benefit of initializing variables (assigning them a starting value) at the beginning of a Scratch project?
A. To make the project run faster.
B. To ensure the variable starts with a known, predictable value.
C. To make the variable visible on the stage.
D. To prevent other sprites from changing its value.
Click to see Answers
1. C. set [variable] to [value]
2. C. For all sprites
3. C. 10
4. C. Images
5. B. when green flag clicked
set [lives] to [3]
6. C. "World"
7. B. To ensure the variable starts with a known, predictable value.