Loading...
Hi everyone.
My name is Mrs. Jenkins.
I can't wait to learn with you today.
Welcome to today's lesson which is called Introducing Variables, taken from the unit, using variables in programming to create a game.
By the end of today's lesson, you will be able to define a variable as something that is changeable.
Before we get started in today's lesson, we have got four key words.
Those words will appear throughout the lesson, so it's really important that we know what they mean before we get started.
Those four words are change, variable, name and value.
Change is to update the value of something in a programme.
A variable is a named piece of data stored in a computer's memory, which can be accessed and changed by a computer programme.
The name is the label given to a variable, so the programmer knows what it is for and the value is the numbers or text stored in a programming variable which can be used or changed.
So those four key words are change, variable, name and value.
Keep an eye out for them throughout today's lesson.
In our lesson today, Introducing Variables, we have two learning cycles.
The first is identify variables in real world scenarios, and then we will move on to using a variable in a coding project.
So let's get started with identify variables in a real world scenario.
Think of a game that you have played that has a score.
What happens to that score when you play? Izzy tells us the score goes up when I collect coins, the game adds more points each time.
Andeep says "My game has lives which go down when I take damage, it also has a score that goes up." and Laura says, "My game changes the score up or down when I get questions right or wrong." Do you play any games that have scores in them? A variable is a named piece of data stored in a computer's memory, which can be accessed and changed by a computer programme.
Variables are used for many different purposes in coding projects.
A variable is a value that can be set and changed throughout the running of a programme.
Look at this scoreboard.
On this scoreboard, there are two variables related to the score.
Can you spot them? There is one variable for the USA score.
The variable is called home score.
We can see that labelled there with the purple square around it.
Number three is our home score, and then there is one variable for the Japan score.
This variable is called away score, and you can see that one has got purple rectangle round it, is our away score.
As the teams play and score points, the score variables will change.
Okay, let's have a little check in, true or false? A variable is something that can be set and changed.
Have a go.
How did you get on? I asked you true or false, a variable is something that can be set and changed.
The answer is true, great job everyone.
Sofia says, "I think variables can only be numbers." Izzy has replied to say, "I think variables can be numbers or letters." What do you think? Variables can be letters or numbers.
On the scoreboard, there are two score variables.
The home score and the away score.
There are also variables for the teams that are letters.
These variables can also change.
So we've got the home team's name and the away team's name.
When new teams play, the team name variables will change.
Let's have a little check-in.
What is home team an example of? A, a variable B, a programme or C, a score.
Have a go.
How did you get on? I asked you, what is home team an example of? A, a variable B, a programme or C, a score.
It is A, a home team is an example of a variable.
Great job everyone.
Okay, we're going to move into task A now.
For task A, I would like you to identify the values of the variables and you will put them into the table.
So have a look at the variables and then you'll have home team, home score, away team and away score.
And you are going to record the value.
And then there is a second one on the next page, which is exactly the same questions, but different teams and different scores, have a go.
How did you get on? I asked you to identify the value of the variables.
So we had two tables to fill in.
The first one, the home team was Ger for Germany, their home score was zero.
The away team was Mex for Mexico and the away score was one, great job.
And the second table we had the home team was Swe for Sweden and the home score was three.
The away team was Kor for Korea and the away score was one.
Great job everyone, well done.
We're going to move on to learning cycle two now.
Use a variable in a coding project.
Look at this Scratch project animation.
What changes in the project? Okay, so I asked you to look at the Scratch project animation and what changes in the project? The score changes.
In this project, score is the name of the variable.
When does the score change? Izzy has helped us out.
It changes when you click on a coloured ball.
Is the change always the same? Clicking on the blue ball makes the score increase by one.
Clicking on the purple ball makes the score increase by three and clicking on the yellow ball makes the score decrease by one.
Great answer, thank you, Izzy.
This is the code that was used in the programme.
So the yellow ball had when this sprite clicked, change score by minus one.
The purple ball had when this sprite clicked, change score by three and the blue ball had when this sprite clicked, change score by one.
Variables are named.
The name is the label given to a variable so the programme knows what it is.
This programme uses the variable that is named score.
So we can see that we have got the code when the sprite clicked, change score, which is the variable, by one.
What is the difference in these code sequences? So we have our blue ball that says when this sprite clicked, change score by one, the yellow ball.
When this sprite clicked, change score by minus one.
Can you spot the differences? The blue ball code increases the score value by one.
The yellow ball code decreases the score value by minus one.
Great job if you got that right.
The program's design can also be shown in a table.
So we have our sprites on the left hand side, the blue ball, the purple ball, and the yellow ball.
And the event which started any of those sprites off was when sprite clicked.
So all three have when sprite clicked.
And then the final column, change in value.
So the blue ball, when sprite clicked add one.
The purple ball, when sprite clicked add three and the yellow ball, when sprite clicked subtract one.
Let's have a little check in.
What will happen when this sprite is clicked on.
So we've got the code over there.
So A, the score variable will decrease by one.
B, the points variable will decrease by one.
C, the points variable will increase by one or D, the score variable will increase by one.
Have a go.
How did you get on? I asked you what will happen when this sprite is clicked on? A, the score variable will decrease by one.
B, the points variable will decrease by one.
C, the points variable will increase by one or D, the score variable will increase by one.
The answer is A, the score variable will decrease by one.
Great job.
Andeep has noticed the value of the score variable isn't changing in his programme.
He says, why isn't my code working? His code says when this sprite clicked, change my variable by one.
Can you see where Andeep has made a mistake? What did you think? Izzy has helped us out.
The variable hasn't been changed.
It needs to be changed to score.
So instead of having, when this sprite clicked, change my variable by one, it needs to say, when this right clicked, change score by one.
There's a little triangle next to my variable.
And if you click on that, you can choose your variable.
In a single programme, you can have different variables.
Scratch has a way to select which variable you are using.
To change which variable your code uses, use the dropdown arrow.
Then you can select the name of the variable that your code will change.
So for the code we've been using, we don't want a variable called my variable.
We want the variable called score so that it says when this sprite clicked, change score by one.
Okay, can I have another little check now? And this time I'd like you to match the word to the definition.
So the words we have, we have variable, name and value.
The definitions, the label given to a variable so the programme knows what it is or the data stored in a programming variable, which can be used or changed and a named piece of data stored in a computer's memory, which can be accessed and changed by a computer programme.
Have a go.
How did you get on? I asked you to match the word to the definition.
So our words were variable name and value.
A variable is a named piece of data stored in a computer's memory, which can be accessed and changed by a computer programme.
The name is the label given to a variable.
So the programme knows what it is.
Value is the data stored in a programming variable which could be used or changed.
Great job everyone.
We're going to move on to our task B now.
I would like you to design your own project using variables.
So you're going to choose three sprites.
You're going to decide on the event that will make the score change and choose a change in value.
Have a go.
How did you get on? I asked you to design your own project using variables, to choose three sprites, decide on the event that will make the score change and choose a change in value.
Here are my examples.
I have chosen a dog, a beetle and a bear.
They're going to action when clicked and then the change in value, the dog will add two, the beetle will add four and the bear will subtract three.
Okay, once you have done that, I would like you to open the project score, which is on our oak.
link/score.
Use your design to create your own project with the three sprites.
When you click on each sprite, the score should change by a different amount.
Have a go.
How did you get on? I asked you to open our project score and use your design to create your own project with three sprites.
When you click on each sprite, the score should change by a different amount.
Okay, so to have a look at our example, you can open the project score example, which is on the oak.
link/score-example.
Here is the code for my animals.
So I chose when this sprite clicked, change score by two for my dog sprite.
When this sprite clicked, change score by four for my beetle sprite.
And when this sprite clicked, change score by minus three for my bear sprite.
Great job everyone, you've worked so hard today.
Let's summarise what we have learned in today's lesson.
A variable is a named piece of data stored in a computer's memory, which can be accessed and changed by a computer programme.
Variables are used in programmes to store different types of data, including number and letter values.
Code can be used to change a variable based on an event.
Great job, everyone, you've worked so hard today.
I can't wait to learn with you again soon.