VARIABLES
SOMETHING THAT VARIES OR CHANGES IS CALLED
VARIABLE.
• In computer programming, variables are used to store data that might change
and can be utilized in the program at a later time. It can be considered as a
placeholder for a piece of information that can change.
VARIABLES IN REAL LIFE
• Score is a variable on a game.
• Person’s age, the season or time of day or type of exam or test scores.
• Height that changes as you get older.
VARIABLES IN CODING
• In coding the term variable refers to a storage or place for holding values or
data.
• Variables are the storage boxes for the computer. Only one value can be
stored in a variable at at time. These values may be expressed as either text
or numbers. The name of the variable never changes; only the value inside it
changes.
VARIABLES IN SCRATCH
• For making a variable, go to variables in the Block Palette and click on the
Make a variable option.
• Write the name of the variable and click on OK.
• Next, tick the checkbox next to the name of the variable to show it on the
stage area.
• To set the variable value, drag the option Set my variable to and drop in the
workspace
STEPS TO MAKE AND PRINT A VARIABLE
• For making a variable, go to variable block in the toolbox.
• Drag set i to option into the workspace and attach under when run.
• To change the name of the variable, click dropdown next to I and click on rename this
variable.
• Write the name of the variable Age and click on create.
• To print the variable value, go to text and drag print block.
• To access the variable value, go to variables in toolbox and drag Age variable.
• Join variable Age with print block.
TIMER WITH VARIABLE
• Choose Nebula background and Rocketship sprite.
• Write the code as per the instructions given below for Rocketship sprite
• Make a variable “timer” and set its value to 0.
• Change the timer by 1 every time when the rocket glides for 1 sec until timer
equals 60 using a repeat until loop.
• Once time is up say, “One minute up!”