Variables are a key part of the new computing curriculum and probably most accessible in Scratch. During the last 2 years I’ve tried a few approaches with varying success; it is the topic that divides the class most. Some get it straight away, some do it and have success with it but are less able to reapply the knowledge and others don’t get it at all. Interestingly, this is also true for teachers!
I am interested in what we can do to help those who are less confident. A definition of a variable as having 3 qualities: a named place, where something is stored and where what is stored can be changed is a great place to start. These are some of the things that I’ve tried:
· Referring to computer games and looking for examples is a good illustration of a variable constantly changing. Eg current score, lives left, high score, time left, time taken,…
· Using the ASK block with questions. This can be for a text input like asking the user’s name or whether you want to play, or it can be a numeric input like what number am I thinking of. The advantage of this is that you don’t need to name the variable and can focus on using it. Referring to it as “answer” illustrates the fact that it has been saved by Scratch in a named place. Also, showing the value on screen as the program runs by ticking the box next to answer illustrates that the value is changing. This method is really helpful in getting used to referring to what is input as the variable name but it can confuse because the variable just exists and hasn’t been named by the user.
· Using a paper cup/box and writing the variable name on it illustrates that data is stored in a named place. I write something on a piece of paper and put it in the cup to illustrate setting the value. When the value is to be changed I write that on another piece of paper, throw the first away and replace it with the second. When you progress to multiple variables you can have multiple named cups to illustrate them.
· Doing dummy runs pretending to be the computer is a bit old fashioned but it has the advantage of being a great debug tool. Scratch 1.4 had a single step option which helped with this but I can’t find it in Scratch 2. I use strips of paper to show the contents of a variable. When the variable value changes pupils cross out the value and replace it with the new one. This process is repeated as the program executes. However, it is important in the understanding of variables to understand that contents once replaced can’t be retrieved; crossing out the previous contents can confuse because the old values can still be read. A more effective learning tool is to fold over the strip of paper and write the new value at the top; that way the old value can’t be seen at all and is gone, though by unfolding the paper at the end there is a record of what happened.
· Difference between setting and changing the value of a variable is not usually a problem, especially if pupils have met the need to initialise other values at the start of a script like size, position, show/hide, colour, etc. Difficulties sometimes arise if the variable value needs to be reset during execution.
· The difference between local and global variables hasn’t been a problem yet, any pupil who has created a script making an understanding of this necessary has understood the explanation!