video

Lesson video

In progress...

Loading...

Hello, my name is Mrs. Holborow.

I'm so pleased you've decided to join me for the lesson today.

We are going to use variables to store values in Scratch, and we are going to create our own chat bot.

Are you ready to make a start? Welcome to today's lesson from the unit Using Fundamental Programming Constructs in a Block-Based Language.

This lesson is called Variables, and by the end of today's lesson, you'll be able to use variables to store values and to trace how they change in a programme.

You'll need to have access to Scratch for this lesson, and it would be useful if you had your worksheet open and ready.

We will be exploring these keywords during the lesson.

Variable.

Variable, a named piece of data, stored in a memory location in a computer.

Value.

Value, the data a variable holds at a particular time.

Trace.

Trace, to track the value a variable holds at any time during a programme.

There are two parts to today's lesson: using variables in a programme, and updating and tracing the value of a variable.

Let's make a start by using variables in a programme.

The story that you are about to hear and read contains some words that are used several times.

Choose what you want these words to be.

You must remember them, or at least write them down on your worksheet.

Pause the video here whilst you think about what you want the value of these words to be.

Okay, hopefully, you've had time to come up with your own values for these words, but just so that I can show you throughout the lesson, I've come up with my own.

So the country, I've set to England, the town to Littletown, the hero to Batgirl, the villain to Loki, and the sister to Aisha.

Computers are good at storing data and remembering it.

It's your job in this activity to play the role of the computer.

So try to remember the data you have just picked, or have your worksheet handy, so that you can refer back to it.

Time for the story.

In a faraway land called country, there was a magical and mysterious castle in the town of town.

It was said that behind the castle walls was a magical ruler called hero.

Hero tried to hide their powers from the people of town, but there was a curious emperor called villain who found out about these powers, and forced hero to run away.

Hero ran away and imposed an endless winter on town.

Their sister, sister, set off on a dangerous adventure to help hero return to town.

Okay, we're now going to replace those values in the story with the values that you chose at the start of the lesson.

I'm going to use my examples here, but you can replace yours and read your story out loud.

In a faraway land called England, there was a magical and mysterious castle in the town of Littletown.

It was said that behind the castle walls was a magical ruler called Batgirl.

Batgirl tried to hide their powers from the people of Littletown, but there was a curious emperor called Loki who found out about these powers and forced Batgirl to run away.

Batgirl ran away and imposed an endless winter on Littletown.

Their sister, Aisha, set off on a dangerous adventure to help Batgirl return to Littletown.

Pause the video here and read your story.

Did your story sound a bit funny? I guess it depends on the values that you set at the start.

A variable is a named piece of data, stored in a memory location in a computer.

In the story, what were the variables? That's right.

Well done.

Country, town, hero, villain, and sister were all variables in the story.

In the story, someone else's value for the variables would've been different to yours, but the story still worked.

Big Ed is your friendly chat bot.

This code has been added to Big Ed in Scratch.

Take some time to have a look at the code carefully.

You can pause your video if you'd like.

What are the two variables in this code block? Pause your video here whilst you have a think.

That's right.

Well done.

Name and answer are both variables in this programme.

Answer is a built-in variable in Scratch that holds the value a user types in.

The variable name has been created by the programmer in this example.

Okay, you're doing such a great job.

We're gonna move on to the first task of today's lesson.

Predict what you think will happen when this code is run.

This is the same code that we just had a look at from the Big Ed chat bot.

Pause your video here whilst you have a look at the code, and predict what you think will happen.

Did you manage to make a prediction? Here's a sample prediction for you.

The Big Ed sprite will say hello and introduce themselves.

It will then call the ask_name subroutine.

The ask_name subroutine will run a sequence of commands that asks the user for the name of their monster, stores that name in a variable, before outputting it in a hello [name] message.

So for example, if we were to use the name Aisha, it would print hello Aisha.

Now, for the next part of Task A, you're going to extend the Big Ed programme by getting it to ask another question.

There are multiple steps to this activity.

A, open the Scratch programme.

B, create a question to make Big Ed ask you what your favourite music is.

C, store the value in a variable called music.

D, make Big Ed respond with "Awesome.

"I love music too." Here's a hint for you.

The ask_music subroutine has been started for you in Scratch, but you need to add in the blocks shown on the slide.

Pause your video here whilst you complete the activity.

Now, for the final activity of Task A.

You are now going to complete the ask_age subroutine.

The subroutine has two lines of code provided.

The subroutine should use the age variable to store the answer.

Big Ed should then say the following two lines: "Wow [age]" for two seconds, "Your monster is much older than me "in the year 2182" for two seconds.

Pause your video here whilst you complete the task.

How did you get on? You're doing a brilliant job so far.

Well done.

For part two of Task A, you were asked to get Big Ed to ask the question about favourite music.

Here is some solution in code blocks.

Pause your video here and compare your solution to this solution, and you can always make any corrections if you need to.

For part three of Task A, you were asked to complete the ask_age subroutine.

Here is a sample bit of code.

Compare this to your answer, and make any corrections that you might need to.

Pause your video here if you need to.

Great work.

You are doing so well.

We're gonna move on to the second part of today's lesson now, and we're going to update and trace the value of a variable.

We're going back to our story now that we saw in the first part of our lesson.

Our story from the first part of the lesson has moved on to a new town.

Therefore, we are going to change the data that the variable town currently refers to.

So we're going to change town to Smallertown.

Remember, you can use your own example here if you want to.

Sister found her way to town, where hero had used their magical powers to build a palace of ice.

Along the way, sister had to overcome many challenges and met a new snowman friend.

Here's the story with my values.

Aisha found her way to Smallertown, where Batgirl had used their magical powers to build a palace of ice.

Along the way, Aisha had to overcome many challenges and met a new snowman friend.

Hmm, this story sounds familiar.

For the end of our story, we need hero and sister to return back to the original town.

As variables cannot hold more than one value at a time and do not remember any previous values, make sure that the data linked to town is changed again.

So town is now returned back to the value of Littletown.

Sister and hero worked together to put the nasty villain in jail.

Hero and sister returned to town to save country from an eternal winter.

The end.

Here's the story with my values.

Aisha and Batgirl worked together to put the nasty Loki in jail.

Batgirl and Aisha returned to Littletown to save England from an internal winter.

The end.

Remember, you can finish your story using the values you set at the start of the lesson.

Okay, time for a check.

True or false? A variable can store more than one value at a time.

Pause the video here whilst you have a think.

That's right.

It's false.

A variable can only hold one value at a time.

If the value a variable holds is updated, the previous value is overwritten.

Big Ed has just arrived on a new planet, and he's measuring the temperature of his new environment.

Is the temperature likely to change? Yes, the temperature will change, so the variable that holds the temperature will need to be updated.

Variables can be updated in Scratch by using two different blocks.

You can update the value a variable holds by using the set block.

You can see here, we're setting temperature to five.

You can also use the change by block.

This block will change the temperature value that is stored.

Here, we're changing temperature by two.

As variables can change during a programme, it is useful for a programmer to trace the value of a variable.

This means the programmer will know exactly what the value of a variable will be at each stage.

It's like tracking the value of the variable throughout the programme.

Okay, let's check your understanding.

Trace the value of temperature.

What value does temperature hold at the end of this code block? Is it A, 5, B, 3, or C, 7? Pause the video whilst you have a think.

Did you put 7? Well done.

Temperature starts at 5, and is then changed by 2, so it becomes 7.

5 plus 2 is 7.

We're now moving on to the final task of today's lesson.

Add the following code to your Big Ed Scratch programme.

Pause the video whilst you complete the task.

You're now going to trace the value of temperature at each stage.

Use your worksheet to state the value of temperature at each stage of the programme.

You'll see that we've highlighted the bits of code that are added at each stage with a box.

Pause the video here whilst you complete the task.

Continue to trace the value of temperature at each stage.

Here is part C.

Here is part D.

And here is the final part, E.

Remember to record the value of temperature on your worksheet.

Pause the video whilst you finish the task.

How did you get on? Well done.

So the value of temperature changes through the course of the programme.

At stage A, the value of temperature is 5.

At stage B, the value of temperature is 10.

At stage C, it's 8.

At stage D, it's 0.

And then at the final stage, stage E, the value of temperature is 6.

Well done, you've done a brilliant job during today's lesson, and I'm so glad that you could join me.

Let's summarise what we have learned.

A variable is a named piece of data, stored in a memory location in a computer.

A variable can be initialised with a starting value.

If the value of a variable is updated, the previous value is overwritten.

You can trace the value a variable holds during a programme.

Great work.

I hope to see you again soon.

Bye.