Variables are a struggle

My students are struggling with variables. The concept of a container that temporarily stores information seems to lose them. Also, they get lost when they are asked to call the variable in their program.

Any help would be appreciated.

to understand variables you must also understand scope and datatypes. though since assignment of data isn’t as important all you really have to worry about is how it’s assigned and when it can be used

Why are variables useful?

well when your having a conversation would you like the person your talking to remember your response or forget it and ask the same question again? variables help us reduce the amount of times we have to repeat ourselves within a given program and save us time if we have to make any changes including the variable were using

Are variables temporary or permanent storage?

variables are temporary as it will only be able to store information while running, if it is reset for any reason it will lose all of it’s memory and will only start storing info once it is running again and it will not remember the previous value it was set at; it will be the value it’s first assigned at

What is a container? And what does it have to do with variables?

a container is exactly what it sounds like, your program is like a big box, of which the starting point is considered “global” of which all rooms have access too. But like with all things you have some things that you’d rather have kept private right? so we create a smaller container like a lock-box or a diary in your room that the bigger container can’t access because it’s in a “private” container that you should only have access too. let’s show an example since this is a bit hard to visualize

// gloabl container
var a = 0;
// private container
function diary() {
var b = 1;
// global variable
// errors out since it doesn't have access

as you can see structuring your code for certain things is important and this is a bit more advanced implicit knowledge that you may run into later when making more complex programs

Hope this helps: Varrience

1 Like


Great points made by @varrience. I have also found this video helpful when introducing variables. I like that it uses score and lives - since every student knows how often these pieces of data changes in a game.

There is also this unplugged lesson. I haven’t used it but it may be helpful if students are struggling with the concept of variables.

Good luck!

Curious, is there one doc where all the UNPLUGGED lessons are listed?

@GordonBrune -

There is this one. :blush:

1 Like