video

Lesson video

In progress...

Loading...

Hello, and welcome back to Selection in Quizzes.

My name is Josh, I'm your computing teacher for this unit.

And in lesson two, we're going to look at selecting outcomes and how we can select different outcomes within the same programme.

You are going to need access to a web browser.

So make sure you have that available.

We're going to be using the Scratch website again.

So remember if you're under the age of 13, and you'd like an account, you will need your parent, carer or a teacher to help you set that up.

Now, remember we don't need an account.

So if you want to continue without one, that's fine, just make sure you aren't downloading any projects after the task or after the lesson.

You're going to need something to write on and with.

So make sure you have that to hand.

And if you've got one of those bits ready, let's crack on with lesson two.

So in this lesson, you are going to relate that a conditional statement connects a condition to an outcome.

To do that, you're going to use selection in an infinite loop to check a condition.

You are going to identify the condition and outcomes in an if.

then.

else.

statement.

And you are going to create a programme with different outcomes using selection.

The first thing we're going to look at then, is recalling repetition.

So you've got two dances on your screen, dance one and dance two.

And there are some instructions for how to complete those dances.

The statement on the screen reads, dance one has fewer instructions, so it will be finished before dance two.

I'd like you to pause the video, and I'd like you to consider whether you agree with that statement.

Do you think dance one will be finished before dance two? Have a quick think.

Okay, welcome back.

Hopefully you've had a bit of time to think then and you've considered whether dance one or dance two, would be finished first.

And it all comes down to repetition.

So dance one has fewer instructions, but it also includes a forever loop.

Now a forever loop is just going to continue, there's nothing to stop it.

So dance two, although it has more instructions is only repeating twice.

So it will be finished before dance one because dance one won't finish.

So using repetition in our programmes is a really important thing to do.

And we're going to look at a little bit more detail, at how that works.

Just recall from your previous learning about repetition.

I'd like you to consider this, what would happen if we ran this programme? So have a look at the programme.

What would happen if we run it? Now, you're going to go and find out.

So what I'd like you to do is I'd like you to open up the short link, go to that Scratch project, run the programme, and find out what happens.

So pause the video, do that now, and resume the video when you're done.

Okay, welcome back.

Hopefully, you've had a bit time then to figure out what happens when you run that programme.

Let's jump into the Scratch site and just see for ourselves.

So we're in this project that was on your worksheet.

it's going to have a quick looking side so I can show you that it is the same code that was on that worksheet.

And we're just going to run the programme and just see what happens.

Great, so I run the programme, I need to press A and nothing is happening.

So it should be turning my sprite clockwise by 15 degrees.

Let's try it one more time.

And again, nothing is happening.

Let's go and find out why.

So we've run the programme and nothing happened.

And that's all down to repetition.

So what I'd like you to do is I'd like you to pause the video very briefly and consider how a forever loop could help.

Resume the video when you've had a think.

Okay, so hopefully you've had a bit of a think there about how a forever loop could help us with our programme here what I'd like you to do is I'd like you to go and test that.

So open up the project again, hopefully you didn't close it down.

Open that up and add a forever loop to the code and run the programme.

See what happens.

Pause the video and have a go at doing that.

Welcome back then.

Hope you had a better time to add your forever loop and run the programme and just check what happens.

And we're going to go back to the Scratch programming now and just have a quick look.

Here we are then.

So let's add that forever loop.

And you could find that in your control section here.

You didn't find that already, go forever loop.

What we need to do is we need to drag this part of our code inside the forever loop.

Add that to when the green flag clicked.

And now we're going to run the programme and just see what happens now that we've added that forever loop.

So I've run the programme.

I'm going to press A.

And as you can see each time I press A my sprite is turning clockwise by 15 degrees.

So now that we've added that forever loop in, my programme runs the way I had intended it to run.

So how did our forever loop change our programme? Well, it affected the way it ran by allowing us the time to press the A key in order to turn our sprite by 15 degrees.

Before we added that forever loop pin, it was just checking once.

And it was checking it very quickly and we didn't have a chance to press the A key.

With the forever loop, it repeatedly checks it constantly.

And checks, has the A button being pressed.

And then if it is, it runs the next part of our code.

And if it hasn't, it recycles round and it says, has it been pressed, no.

Has it been pressed, no.

So it continuously checks whether or not the A key has been pressed.

And we're going to use repetition and the forever loop a little bit later in our programming.

The next thing we're going to look at is different outcomes.

So we've looked at how the if, then code block works and we've looked at if something's happening if the A key for example is being pressed, then do this.

But we can also look at it using different outcomes.

And that's where this if, then, else block comes in.

So the code on the screen shows if it is raining, then thumbs up.

Else, thumbs down.

So what that means is if I was to be doing this programme at the moment, where I am it's very sunny.

So I would have my thumb down.

And I would keep it down because it's not raining yet.

So we have, if it is raining, which is our condition it must be true or false.

Is it raining? Yes or no.

It's not raining here, so no.

We have outcome if the condition is true.

So if the condition is true, if it is raining, we have our thumbs up.

And if the condition is false, we have outcomes for that.

So if the condition is false, it's thumbs down.

So else, thumbs down.

And at the moment, as I said, mine would be thumbs down.

So what I'd like you to do now is I'd like you to go back to the programme.

And I'd like you to add a programme for the dog sprite.

And you can do that by clicking on the dog sprite in the right-hand corner.

And there are some blocks available for you.

And you'll have to find the other blocks to help you.

But you have got the algorithm on the right hand side of the screen to help you.

And it will be on your worksheets.

So you're going to have a programme that says if key A is pressed, then move 10 steps, else turn clockwise.

So add that to the dog sprite in your programmes.

Open up the link or go back to the programme if you still got it open.

Click on the dog sprite, create a programme using the algorithm on your worksheet.

Welcome back.

Hopefully you've had a bit of time then to create that algorithm field dog sprite.

Let's jump into the Scratch programme and just see how that works.

So let's open up the dog's sprite down here.

And you can see there were already a few command blocks for you to help you with this.

Now, the algorithm we were going to create was if key A is pressed, then move 10 steps, else, turn clockwise.

Didn't give you any more information than that, so you could choose how much to turn clockwise by.

But let's start by popping out if key A is pressed then, they had to move 10 steps.

We had to find the else, didn't we? So let's go and find the else, which was turn clockwise.

I'm just going to keep it at 15 degrees for now.

We need an event block to start our programme and we need it a forever loop.

Remember if we didn't have that in it would check once and then it wouldn't run again.

So let's see if that has worked.

And there you go.

You can see my dog sprite is spinning on the spot because it is turning 15 degrees.

And that's because the A key hasn't been pressed.

If I was to press the A key now, you can see it moves very minorly because it's only 10 steps.

And it will move in the direction that the dog is facing at that time.

So it doesn't always go straight across the page.

And you can also see that my cat sprite is spinning on the spot because again, that was the A key that was needed to be pressed in that programme.

So hopefully, you remembered to add your forever loop.

That was a really important part of that programme because if we didn't add it as with before, we wouldn't have been able to see our programme run.

It would have run one time, you've had seen your dog turn 15 degrees and then it would have finished.

And you wouldn't have been able to do anything about that.

You would have been able to press the A key it wouldn't have done anything, your dog wouldn't have continued to spin.

So it was all down to that repetition that that happened.

And that was the reason they're continuously spun when nothing was happening.

And when you press the A button, it moved 10 steps.

You're going to move on to designing and coding your own conditional statement with two outcomes.

And you're going to use something similar to this design template.

And you have this on your worksheet.

So you're going to have an if, a conditional statement, then you're going to have an outcome, if your conditional statement is true.

And an outcome if your conditional statement is false.

On your worksheet, you have a number of different conditional conditions.

You also have a number of outcomes to add in if your condition is true and you're having a number of conditions to add in if your condition is false.

Sorry.

Your actions to add in if your condition is false.

So open up your worksheet, have a check through that.

Pick a condition, a true outcome, a false outcome.

Add more than one, if you're feeling fancy.

Construct a programme and check that it runs.

So you need to check that it runs afterwards.

So pause the video, have a go at doing that.

Resume the video when you're done.

Okay, welcome back.

Hope you've had some time then to add your condition and you selected some outcomes for true and outcomes for false.

More than one if you were feeling a bit fancy, as we said before.

We will talk about it at the end and we'll give a bit more detail then.

But if you would like to share that project with us, please consider doing that.

We'd love to see them.

We're going to move on to the last little bit before we finish for today.

So we're going to look at explaining outcomes.

The statement on the screen reads, "when I watched the program's output, "the sprite moved off the screen." Pause the video, consider why that happened? Okay, welcome back.

Hopefully you've managed to see that the reason that happened is because it's moving 10 steps each time and that's in the else part of our code.

So if that's in the else part of our code, it that's going to continue to happen until the Q button is pressed.

When the Q button was pressed, it made a meow sound, and then it continued moving.

So eventually that's going to move off the screen.

So that's something to be considering when you're doing your own programmes.

Is that, where your sprite's going to end up, if you've got that as an else condition.

Okay, the next one, "When I was watching the program's output, "I heard the sprite make a meowing sound." Why did that happen? Pause the video, have a look at the code and explain why that happened.

Okay, so hopefully you can see them.

The reason it played the meowing sound is because somebody pressed the Q button.

That's our then statement.

If someone presses the Q button, then play the sound Meow.

So somebody has to press the Q button for this programme to make that meowing sound.

So hopefully, what we're doing now is we're starting to understand why certain things happen, why certain outcomes happen when our code is run.

And that's really important to be able to look at a piece of code and understand how it works.

If we are then going to modify that code in the future.

So that's the end of lesson three.

I hope you enjoyed playing around in Scratch, adding some of those conditions and those certain outputs, the true outposts, the false outputs.

And you've had a good time experimenting with that.

As I said before, if you would like to share your project with us, we would love to see it.

So please consider doing that.

If you would like to do that, you can ask your parent or carer to share it on Instagram, Facebook or Twitter, tag @OakNational and #LearnwithOak.

I've really enjoyed this lesson.

I'm really looking forward to lesson three and I'm hoping that you are too.

So I look forward to seeing you then.