video

Lesson video

In progress...

Loading...

Hello, and welcome to lesson two of our programming unit.

I'm Ben, and this lesson is all about variables.

Now, all you'll need for today's lesson is access to the website, Scratch.

And if you're under 13 and you'd like an account to say, be able to save your work.

You'll need to ask your parents or carers or teachers to set you up with an account in advance.

So if you can clear away any distractions that you have put your mobile phone away.

Maybe if you can find a nice quiet place to work, that'd be brilliant and when you're ready, let's begin.

Okay.

So in this lesson, we're going to define what a variable is.

Then we're going to look at how input process output works and how it relates to computers.

Then we're will trace the value of a variable, and then we'll have a go at coding, a sequence to include a variable.

Now to get us started.

We're going to have a go at story time.

Now I want you to relax a little bit because you're going to hear a story, but don't relax too much because you're going to play an active role in this story.

So the story that you're going to hear has some words that you'll hear a number of times.

So what I'd like you to do is pick what those words are going to represent, but you must remember them.

So I don't want you to write them down at all.

You must store them in your memory, in your brain, but there can be whatever you like.

So you all going to make them up.

So I would like to think about what country would you like our story to be set in? And remember this can be fun to see if you want it to be.

It can be real I don't mind.

Think about what town you would like it to be in.

I'd also like you to think of a hero.

Now, the hero could be you.

It might be male or female or complete a fantasy name maybe.

I like to think of a bad person.

So a villain who's going to be in our story.

And also the main character is going to have a sister.

So think about the name for the sister.

Now, if you want to pause it now, just to kind of make up those words and remember them, that's absolutely fine.

And you can unpause when you're ready, but remember don't write them down.

'Cause I would like you to really think about storing them in your head, okay.

So the reason that we're doing this is because computers are really good at storing data and remembering them, and remembering the data.

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

Now computer programme has used variables to link data to words.

Okay, so the variables in our story are going to be country town, hero, villain, and sister.

So every time you see one of those words in the story, I would like you to say it out loud.

Okay? So I'll read the story and every time you see the word country in square brackets, and I'll point that out to you, I'd like to replace country with a country that you've made up for the one that you want to use in the story, okay.

So when we're ready and when you're sitting comfortably, we will begin.

So part one.

So in a far away land called, this is where you've got to put in country.

So in a faraway land called, there was a magical, mysterious castle in the town of town.

It was said that behind the castle walls was a magical princess called hero, Hero tried to hide her powers from the people of town.

But there was a curious Prince called Prince villain, you can say villain who found out about these powers and forced hero to run away, okay.

Part two hero runaway and impose an endless winter on town her sister, sister, set off in a dangerous adventure to help hero return to town, so we'll take a short break.

Let's take an interlude.

How are you getting on with that? Hopefully you've got all the words still stored in your head, but now our story have moved on to a new town and therefore we're going to change the data to that town called refers to sorry to a new town.

So I went to, erase from your memory, what was previously stored for town.

So your old town has gone and I like you to think of a new town for the next part of our story.

So when you hear town replace it with the new town that you've got, okay.

So part three, are you ready? So sister found her way to town where her sister had used her magical powers to build a palace of ice along the way, had to overcome many challenges and meet a new snowman friend.

We'll take another interlude.

Now for the last part of our story, we need our hero and sister to return back to the original town.

So again, get rid of the new town off your memory and put the old town back in your memory.

Those variables, don't hold more than one item of data at the same time.

And they don't remember any previous values, make sure that the data linked to town has changed again.

Okay.

So it doesn't store the previous ones only the one most recent one.

So, get rid of the first town, get rid of the second town and then your new town is the original town, got it? Right.

Okay.

So we're back to our original town anyway.

So last part of our story.

So remember, you've got to replace the whispers with words.

So three, two, one, sister and hero work together to put the nasty villain in jail.

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

The end.

That's pretty good story actually.

I think it would make a really good film.

Anyway.

So what we've learned about variable so far, okay.

Hopefully you paid attention to that and you understand some key parts of what we talked about.

So variables, now a variable as a name that refers to data being stored by a computer.

So I've got two questions for you relating to that.

So question one in the exercise that we just did then what were those variables? Okay.

And then the second question.

Did any of the variables store more than one item of data at the same time? So can you pause the video and then we'll go through the answers when you thought of your answers and you're ready.

Okay.

So the first question.

Question one in the exercise, what were the variables? Were your variables are all the things that I asked you to hold in your memory, such as country towns, sister, hero, villain, all of those were variables.

So they were items of data linked to a key word.

So you and your memory, your memory is in your brain.

You, every time you saw country, you picked up what you had linked to that word.

Okay.

And then question two.

Did any of the variable store more than one item of data at the same time? Well, the trick here is.

The trickiness of the question is that we use the word town as one of our variables, but the question is, did town store the more than one item at the same time? And the answer is no, it didn't.

It only stalled one.

Although we changed the name of our town twice, and one of the times reverted it back to the original meaning or the original word that we linked to it actually at any one time, town was only storing one value and that's a really key point.

Okay.

So we'll move on.

So now we're going to look at input process outputs.

Okay.

So to represent input, process, output.

Okay to represent input, process, output we got a lovely little diagram for you the screen of a computer.

So you can see that computers take inputs, they then process those inputs, and then they produce an output.

And if you remember from last lesson, we introduced you to three key terms that we're going to look up throughout this unit, which are sequence, selection and iteration.

Now they'd all fit inside the process area.

So your computer can take an input and that can be by the human.

So for example, it might be a mouse click or typing something in on the keyboard.

It might be voice activated, or it might build to massacre as well.

So it might be a sensor of maybe that records, some kind of movement or temperature, the process that happens produces an outputs.

So if we're thinking about the keyboard analogy, you would type something on your screen, your computer then processes that information, and then you can see it appear on your screen.

If there's a word processor, for example.

Now the storage comes in and that's demonstrated by the activity that we just did.

So sometimes computers need to recall some memory or some data that's stored.

Then it needs to recall at the right time to be processed.

So those variables is a great example of that.

When in your head, you were listening to me as giving you the story.

That will be the input, and then at the right time, when I said country or one of my other variable names, you then accessed your memory.

So your storage in your brain and you processed it, and then you output it by saying the word at the right time.

So let's now move on to variables in Scratch and build on what we started last lesson.

So I want to meet big Ed now.

So big Ed is your friendly chatbot.

Now your task is to answer the task one questions on the worksheet.

And you'll find out what the code does and have a chance to experiment with it.

So I'd like to navigate over to your, worksheets in a second, okay.

And then you're going to have a go at a task one.

Now task one is just predicting what you think the code will do.

So spend time reading the code on the right hand side, as you can see here.

Predict what you think will happen.

Then you've got to run the Scratch code from the link provided on your worksheets, and then think where your predictions correct? Did anything surprise you about the code that you weren't expecting? And then did you miss anything out? So there's no pressure here whatsoever.

I'm not expecting you fully to understand exactly what to do.

And so it actually what the code does, but I'd like to read through it and see if you can work that out, okay.

Write down what you think, what it does and then run it.

So run the code and then again, just document did it do what you thought it was going to, and then of course, if there's anything different from your prediction to what actually happened, then just make a note of what those things are, okay.

So I'd like to pause the video, now have a go at that.

And once you've done that prediction and you've run it, then I'd like to start the video again.

So hopefully you've had a chance to predict what you thought the code was going to do, and then you run it and then made a comparison to what actually happened against what you predicted, what you thought was going to happen.

So I've clicked on the link and I've selected, see insights, so I can see the code.

Now what happens here? So I can read this.

It says when the green flag is clicked.

So that's when I click on this and I'll start my programme.

So when I click on that, I think it's going to say hello for two seconds.

And then It's going to say, I'm big ed from the year 2182 for four seconds.

And then it's going to go to ask name.

So it's going to follow through this sequence of code, and then it's going to call this sub-routine.

Now, if you remember from last lesson, we looked at these kinds of these ready kind of blocks.

And we recognise that that was a sub-routine.

So the define ask name that's just sub-routine and this bit here is calling it, activating it, telling it to do that sequence of, to execute that sequence of code.

So I think it's going to then do that.

So after it's done those two things is going to then execute these blocks of code.

So it's going to ask me what my name is.

Then it's going to set my name to answer.

Now, can you think what answer is? What keyword we learnt this lesson so far, that might be that I'm storing a value against a word.

Okay.

So that's a variable.

So then it's going to say hello, and there's going to retrieve that name, that variable, and then say my name for two seconds.

That's what I think is going to happen.

So let's test that out.

So I'm going to click on the green flag going to say hello for two seconds.

Say, I'm big Ed from the year 2182 for four seconds, I'm going to call myself routine and you can see that happen now.

So it has asked me for my name.

So I'm going to type in my name.

And then it says, hello, Ben for two seconds.

Perfect.

Okay.

So I'm going to head back to the slides.

Now we've done our prediction.

Now it's time to investigate exactly how the code works.

So I'd like to continue with the worksheet and complete all the questions for test two.

So what you've got to do is follow the instructions and really investigate how the code works.

So the questions will guide you in terms of what parts of the code to look at when and see if you can just run the code and see if you can really try to understand what each section of the programme is that actually doing.

Okay.

Now document your thoughts.

And then when you finish that, we'll go through the answers a bit later.

So I'm going to ask you to pause the video and move over to your investigate tasks.

And like I say, when you finish the investigative steps, then come back to the video and we'll go through some of the answers.

So hopefully you've had a chance to go through the investigative steps and you've really kind of tried to unpack how some of the blocks of code inside the programme that we gave you, how they worked.

Now what we're going to do is we're going to go through the answers, but don't worry if you've got any of them wrong.

It's absolutely fine.

So what I'd like to do once I've gone through all the answers, it would be really nice.

If you could go back to your answers and either correct some of the mistakes that you made, or if you've felt that I said something that helped to expand or made things a bit more clear then to what you answered, then what would be really great.

Again, if you go back to your worksheets and maybe add a little bit more detail, and maybe in a different colour to help you to see what the changes that you made where okay.

so let's go through the answers to the questions.

So the first investigate task was to how do the two blocks relate to each other? So the ask name, and then they define ask name.

How do they relate to each other? Well, the answer is that when your programme reaches the ask name block, it calls such sub-routine define ask name.

So we talked about that before.

So define ask name is a sub-routine that's us telling our computer, our programme, what ask name is.

So when it hears ask name or when it gets that line of code ask name, it knows then what to do.

So we can see on the right hand side, we've got, define ask name, and then we've defined the sequence of code of what to complete after it's being called.

But when it got called, you can see when the green flag is clicked it's going to say, hello, say I'm big Ed from the year 2182, and then we're going to call that sub-routine there.

Now, if you remember back to the previous lesson, when we did frere Jaque, each line of, frere Jaque repeated twice.

So we have frere Jaque, frere Jaque, dormais vous, dormais vous Now we take dormais vous we code it out under a sub-routine.

So we defined what dormais vous was.

We code it what the music was for that segment, that sequence of music for that segment of dormais vous part.

And then we called it twice.

So rather than some to write out all the lines of code that made the music twice, all we did is we put it once in a sub routine, but we called that sub routine twice.

Okay.

So I hope that makes sense.

Now, next one, investigate the answer to this bit.

So I, you to take out that line of code.

So ask what is your name and wait.

So you're meant to remove that from the code, run it again, and then make a note of any changes that then happened.

So what changed about it and why do you think that was okay? Well, big Ed will now say just hello.

So as the question has not been asked, there was no answer.

So the line set name to answer will now give an empty value.

So we go through the three lines of code that remain.

So define us name, set, name to answer, and then say hello name, Now because answer has not been asked there's no question being asked.

There's nothing answer answers empty.

Therefore name is empty so we can say hello, and then empty value.

So all you're going to see on the screens is hello.

So the next one is below define ask_name.

There are two variables being used.

So what are their names? Okay.

Hopefully you got that.

And the answers were Answer and Name.

So once we asked that question, it stored the answer to the question under a variable name, called Answer, we then set name to answer, and then we said, hello, and then the name.

And then I think the final question and this, we asked you to put that block back in, but put it back in a different place this time.

So it said, why do you think it only says hello and not hello and the name you entered? And what can you learn from this? Well, the reason it says that is because name has been linked to answer before the question is being asked.

So at this point in my code at this point in the sequence, then answer is empty.

Therefore an empty value has been set to name.

So name is therefore empty.

Then we ask what your name is, but we don't redefine name at any point with our new answer.

So answer then has a value, but actually name is not being reset to that.

So it's still going to say hello, and then, an empty name.

And the key learning point to learn here is that you must always set the value of the variable before using it.

Okay.

That's key.

So I'm going to give you a moment and a second to go back to your worksheet and make those changes to investigate steps.

Should you want to, or if you feel like you could add a little bit more or some questions wrong, but then what I'd like to do is move on to the modified tasks.

So you continue with the worksheet, complete all of the question sorry for task three, following instructions and modify the parts of the programme that aren't currently working.

So, so far in today's lesson, we predicted what we thought was going to happen.

We've investigated the code that's there constructed and working.

So the next challenge really is for you to modify the programme yourself, make changes to the programme and see if you can get a working programme by the end of it.

So have a go at that.

And when you've done that, We're going to go through the answers.

So if you can pause the video here, go back to your investigates, completely modified tasks.

And like I say, when you've done all that, you can restart the video and we'll have a look about how you modify that correctly, okay.

So I'll see you then.

Okay.

So how did you get on with the modified tasks? Now, don't worry if you didn't complete all the tasks, because I'm going to go through how you did it right now.

So wherever got up to just compare how I did it to how you did it.

So the first part was to complete the ask music section.

Now for this task, I gave you all the blocks.

It was just your job to put them in the right sequence, in the right place.

So we've got a defined ask music.

And then we said, ask what music do you like and wait.

Then we're going to switch the costume to this big Ed.

Let's just have a look what that does so far.

So I'm going to put in ask music.

So it's going to ask my name, then go to music.

So let's run them through this code, but I'm just going to make sure I can see the code when I run it so I can get an understanding of what's happening so far.

So remember, it's going to start off with the hello.

It's going to say I'm big Ed from the year 2182.

That's going to ask me for my name.

I'm just Ben, 'cause it's running this sub-routine here.

Here we go, it's saying hello, Ben, and then here we go.

Right, so it's going to say, ask what music do you like and wait.

So I'm going to put in my music.

I love the Beatles 'cause who doesn't? Okay.

So the Beatles, there we go.

And it just put a question mark.

And actually I switched costumes.

So that's kind of what we thought was going to happen.

Switch costume to that.

So what I'm going to do is, I'm going to see if I can fill in the rest.

So it says set music to zero.

Okay, now I've got a variable called music here and I don't want it to be zero.

I'd like the music variable to be maybe the answer that I wrote in before the Beatles.

Now, if you remember from looking at this block here, that defined ask name here.

So, it says what is your name then set name to answer.

So I'm going to follow that same path and again, so this time rather than set name to answer So I'm going to set music to answer because I've asked this question here, what music you like? And I want the answer to be stored on the music.

And then we can say, it said, we wanted to say awesome.

I love that music too.

So, and I put this in.

So it's going to say, awesome I love what to well music I put in the Beatles.

So I want to say awesome I love the Beatles too.

So we've got music, joined music here.

'Cause remember the Beatles.

If I was answering it, music would be set to the Beatles.

But if you were answering it it will probably be something much cooler than that.

Although I don't believe you, if there's anything cooler than Beatles, you just wrong.

Right? So it says, I love music.

I love the Beatles.

And then I also wanted to say join to that, to that question mark here too.

And then your name.

So I love the Beatles too, Ben.

That's what I wanted to say.

And then I wanted to go back to the normal costume.

So I'm going to pop that in there.

Okay.

So let's test that out one more time.

So I'm going to run this again.

So hello.

I'm big Ed.

It's going to ask me to find name, 'cause remember it's going to run this sub-routine here.

Oh, let's move this across.

That was that problem moving across.

There we go.

So it's going to, let's move this so you can see it.

So it's calling this sub-routine now.

So I'm going to type in, Ben I can say, hey Ben, or hello, Ben, I'm going to be precise.

What music do you like? I like the Beatles because the ACE.

So it's going to then hopefully change costume, search costume to that.

Then it's going to say awesome I love the Beatles too.

So let's have a look.

Awesome I love the Beatles too.

And then switch to the previous costume.

Now it was already started off in that costume to start with, so it didn't switch to that costume.

And that's because at no point in my programme, am I telling it to change costumes at the beginning So as when I last run it, big Ed was going that kind of movement there.

Then I didn't reset it.

Okay.

But I have now.

So it all starts off with that.

So I've got that working.

Okay.

So that's great.

Now the last one to do was ask name.

So when I'm going to pop that in there, so it will ask name, ask music and ask age.

Sorry.

I said name, I mean ask age.

So you're saying how old are you? And then wait, now the task was, I'm just going to check out my task.

It says after that, it should say, wow.

And then your age for two seconds.

And then it's going to say you're much older than me in the year 2182 for two seconds.

Okay.

That's all I want it to do.

So I'm going to look at the previous structures again.

So presumably I want that line there set music to answer, but not music, if I click on variables here, I've actually got a variable called age.

Okay.

So I'm going to set age.

Okay.

Not to zero, but to answer.

So look at the colours because the colours are always really helpful in Scratch because they give you an indication about which parts of these block of codes we want, because it's like light blue kind of colour it's under sensing.

And you can see, hopefully I've got a variable called answer that, can pop into that.

So I can drag that and I can pop it inside that zero.

So now I'm going to set age to answer like that.

Okay.

Then it's going to say wow age for two seconds.

So let's have a look.

We want the say block that's up purple.

So I'm going to pick on that.

So I need to say, okay, so I'll pop that in there.

So rather than hello, I wanted to say the age for two seconds, but also the word wow.

So I need that green block, which has joined.

So I'm going to go to my operators here.

I'm going to join, slot that in there.

I'm going to put my variable in there.

So, well actually, no, I'm not.

I'm going to say, wow.

So I'm going to put, wow.

And then the age inside, instead of banana, I'm going to put age.

So I'm going to click on that, get my age valuable.

And I'm going to drag it into ask as banana.

So hopefully that will now say wow age, for two seconds.

And then it can say you're much older than me in the year, 2182.

So I'm just going to pop this in here.

I can change it to think you're much older than me in the year 2182.

Now that's kind of that doesn't really matter.

There's overlapping with my music there, but I'm just going to move out of the way so I can see it.

So let's give our code one last run through and fingers crossed, it all works.

So we should have ask name, ask music, ask age.

So it's going to say hello, I'm big Ed from the year 2182.

That's going to ask me my name.

You're sick of hearing my name now, but I'm put it in again.

I go, Ben, okay.

Hello, Ben.

Then it's going to call my ask music.

What music do you like? Beatles and then it's going to switch costume to the wrong kind of costume that's going to go.

There we go awesome I love the beetle to Ben and then come switched back to normal costume is then going to run my ask age sub-routine, which is how old are you? I'm just really older then if I can put really old in there, but like, I'm just going to put 100.

Okay.

I'm a hundred.

And then, enter wow a hundred.

You're much older than me in year 2182.

There we go.

Success.

We've managed it.

Okay.

So again, if you didn't do all of that, then again, why don't you pause the video now? And you can see my code on the screen and see if you can construct it to match my answer as I've got it.

Okay.

So we've reached the final activity for today's lesson.

Okay.

Which is tracing.

So let me set the scene for you.

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

So use a task foUr activity on the worksheet to trace, which means to keep track of the volume of the temperature variable on each line that is referenced.

So what that means is you need to go through the worksheet.

So I go through these lines of code.

You'll see that each one, the orange blocks sets the unchanged at the value of our temperature, variable.

And I'd like you to note down what the output would be.

Every time that big Ed says the temperature.

Okay.

So I'd like to, again, pause the video, go to task four, complete the worksheet.

And when you've written down the answers, we'll go through them.

See when you've done that you can unpause and we'll go through the answers then.

Okay.

So we're going to go through answers now.

So what did big Ed sorry say on each line of the code? So you see here.

So when the green flag is clicked, we're going to set temperature to five and then it's going to say temperature for one second.

So the first time he says anything, the volume of the temperature is five.

Now the next time he says something, we've got another line of code, which changed the temperature by five, so it was five.

Now we've got overwritten it by adding five to it.

So the next time he says something, they get should be saying, see if you can say it, you should be saying three to one 10, okay.

Because we changed it by five.

So it was five.

We changed it by five.

So it's now 10.

So this time we're changing the temperature by minus two.

So currently temperature is 10, but what overwriting the value of that variable by taking two away from its previous value.

So 10 minus two and three, two, one is bigger.

There's going to say eight.

So temperature code it starts at eight.

So temperature is going to be eight.

So next one is set temperature to zero.

Now a tricky one this one.

With big Ed, say zero next time.

Or is he going to say eight? So let's say three, two, one.

It was zero.

It's not changing it by, by zero.

He's setting it to zero.

Okay.

So set temperature to zeros.

His temperature is now zero.

And then finally change temperature by six.

So three, two, one.

It is going to be six.

Perfect.

Well done.

Okay.

So hopefully you got the idea of tracing their.

Tracing is a really important skill because it really helps us plan out and understand what's happening with our programme.

So we look at the value of the variable temperature there.

We can trace and track what his value is at each stage of my sequence here, okay.

So that's it for today's lesson.

Now I hope you've really enjoyed that lesson and I hope you enjoy the learning for the rest of your day.

Now it would be really, really great.

If you could share your work with us, maybe you could take a screenshot of your scratch programme or maybe a little video of it.

That'd be really wonderful and we would love to see it.

And if you'd like to do that, please ask your parents or care to share it on Instagram, Facebook, or Twitter and tagging Oak National and LearnwithOak.

Okay.

And that's it for me.

And I'll see you next lesson.