-
Introduction
-
Introducing Scratch
- Scratch Ideas
-
Activities Overview
- Scratch Activities Project
-
Algorithms and Programs
-
Write an Algorithm
-
- Sequences
- Loops
- Data: Variables
- User Input
- Conditionals
- Conclusion
What are Variables?
What are Variables?
In Scratch, and Coding in general, a variable is a name for a value (for example: a number like 5) that can change.
For example, look at the blocks in the below image.
In the example above, we have a variable called number that changes as we move through down the stack of blocks.
What happens when you click this stack of blocks?
- The number variable's value is set to 2.
- The cat will say the value of number (2 at this point) for 2 seconds
- The number variable's value is then set to 4
- The cat will say the value of number (4 at this point) for 2 seconds
Variables are an essential way of representing Data, which are used in most programs.
For example, if we made a basketball game in Scratch and wanted to keep track of each team's score, we would need to use two variables: one number variable for each of the teams. These variables (let's call them Home Team Score and Away Team Score) would start with a value of 0 and then every time one of the teams scored a basket, the value of the appropriate variable would be increased by 2.
Views | |
---|---|
1 | Total Views |
1 | Members Views |
0 | Public Views |
Share by mail
Please login to share this webpage by email.