Lesson video

In progress...

Loading...

Hello, my name is Ms. Powell and welcome to Computing.

I'm so pleased that you decided to join me here today.

In today's lesson, we are going to test a quiz which uses selection.

Let's get started.

Welcome to today's lesson from the unit Using selection and programming to develop a quiz.

Today's lesson is called Testing a Quiz, and by the end of today's lesson you will be able to create a programme that uses selection.

We'll be using these keywords throughout today's lesson.

Let's take a look at them.

The first word is condition.

Condition: this is a statement that can be either true or false.

The next word is test.

Test: this means to run a programme to check if it works the way that you planned.

Lesson outline, Testing a quiz.

Today's lesson split into two sections and in the first section, we'll programme a quiz and in the second section we'll test a quiz.

Let's get started with the first section Programme a quiz.

In programming, what is selection? Andeep says, "Selection is part of a programme where if a condition is met, then a set of commands is run." Sam says, "Selection checks a condition, such as seeing if an answer is correct." Today you'll be creating a Scratch quiz.

You'll use selection in your programme to check if a user's answer is correct or incorrect.

Your programme will have a different outcome depending on the condition.

You'll use your quiz design sheet to guide your programming.

Here's the example of a quiz design sheet.

We've got the start.

Then ask the user: True or false? Jupiter is the largest planet.

That's the question.

The answer is True.

That's our condition.

Is the answer true, yes or no? The programme is checking to see if the user inputs the word True.

If true, then say "Correct!" and change costume to planet.

If the user inputs anything other than true or misspells the word true, the answer is false.

Else say "Incorrect!" and flash sprite red.

This quiz design sheet can help to guide our programming when we start using our blocks in Scratch.

If you don't have a quiz design, you can use this one.

This is the plan for one question.

A branching algorithm has been used to show the true and False outcomes.

Just like the branches of a tree, we can follow this algorithm to find the outcomes if the answer is true or false.

What is the first question? Pause the video and have a quick think.

Well done.

The first question is: True or false? Jupiter is the largest planet.

Where is the condition? Here's our condition.

Answer equals True.

This is a true or false question where the condition is True.

To create a quiz question in Scratch, you'll need an event block to trigger the start of the programme.

Here we've got the When this sprite Clicked event block.

You then need the Ask and Wait block to let you ask the question.

Can you see it here in blue? Ask and Wait And there's a space there, a circle for you to type in your question.

The answer block will contain the value of exactly how the user typed it.

It fits inside an equals operation block.

answer equals You set the condition in this space.

So here we've got our answer and we've put it inside an equals operation block, and we have a space here to type in our condition.

So that's the correct answer.

In the case of true or false, is Jupiter the largest planet? Our answer would be True, and we could type that into the circle there.

This is how this would look in Scratch.

When this sprite clicked ask True or False? Jupiter is the largest planet and wait.

If answer equals true, then.

So we've got a space here to put our outcome if true.

This would be say "Correct!," or else if the condition is not met, say "Incorrect!" When you run the programme, the sprite will show the question in a speech bubble.

True or false? Jupiter is the largest planet.

Here's my question.

A text bot prompt will show at the bottom of the screen.

This is where the user will type in their answer.

This is the user input.

Can you see it there at the bottom of the screen? Aisha says, "I'm not sure which block should go in the 'then' section and which one should go in the 'else' section.

What can Aisha do? Pause the video and have a quick think.

Fantastic thinking.

Aisha could check her quiz design for the next step.

Aisha could try the code 'then' and 'else' and then test her programme.

Here's my branching algorithm.

If the user's input matches the condition, the True outcome will happen.

Here's our condition.

And this is our True outcome.

So if the user inputs True, then the programme will say "Correct!" and change costume to planet.

If the user's input doesn't match the condition, the False outcome will happen.

So if the user doesn't put in the word True and puts in anything else, such as "False" or "No," or even if the user inputs "Yes," then the programme will say "Incorrect!" and flash sprite red.

So even though "Yes" is a correct answer, is Jupiter the largest planet? It's not what our condition is checking for.

The condition is checking for the answer true: T-R-U-E and it needs to be spelled correctly.

This is our False outcome.

say "Incorrect!" and flash sprite red.

I need your help.

I'd like you to have a little look at the code.

We've got code A and code B.

Which code will make the sprite move if the condition is False? Pause the video and have a good try.

Well done for having a go.

If we read through the code, for A, we can see when green flag clicks, that's the event block, say "Welcome to my quiz" for two seconds.

ask Is Madrid the capital of Belgium? and wait.

If the answer equals no, then change colour effect by 50.

Or else say Wrong for two seconds.

Let's look at B.

When green flag clicked, say Welcome to my quiz for two seconds.

Ask Is Paris the capital of France? and wait.

If the answer equals yes, then say, Well done! for two seconds or else move 10 steps.

Both codes have a condition.

In code A, the condition is answer equals no.

True or false? If the player inputs No, that's true, then change the colour effect by 50.

If the player does not input the word No, then the programme will say Wrong for two seconds.

If the condition is False, in code A, the sprite will say Wrong for two seconds.

It doesn't move.

If we look at the code in B, the condition is answer equals yes, true or false.

If the player inputs yes because Paris is the capital of France, then the sprite will say, Well done! for two seconds.

Or else if the player inputs anything other than yes, that's the incorrect answer, the sprite will move 10 steps.

In code B, the sprite moves if the condition is false.

Which code will make the sprite change colour if the condition is true? Pause the video and have a quick think.

Is it code A or code B? Well done for having a go.

It's code A.

I can see it here: Change colour effect by 50.

If the condition is true, then say "Correct!" for two seconds and change costume to planet.

Think about what actions you want your True outcome to have.

You could have more than one outcome.

For example, our sprite here says "Correct!" for two seconds but also changes their costume.

If the condition is false, then say "Incorrect!" for two seconds, change colour effect by 170, turn sprite red, wait 0.

5 seconds.

Set colour effect to zero, turn sprite back to regular colour.

This is the outcome if the condition is false.

The sprite will say "Incorrect!", flash red and then turn back to its original colour.

Aisha says, "I tested my colour values to get the effect that I wanted.

I put the wait block in so that the colour change can be seen." If you had a longer wait, then the colour change would last for longer, and a shorter wait makes it appear like a flash.

Use your quiz design sheet to check that your True and False outcomes are correct.

I have a task here for you.

You're doing really well.

I'd like you to programme your first question and answer quiz on Scratch.

Your programme should have ask and answer blocks, a condition, an if, then, else block, a True outcome and a False outcome.

Pause the video to finish the task.

I'd like to give you some feedback.

Open the project oak.

link/solar-system-1.

Here you can see an example of the code: when the sprite clicked, ask true or false: Jupiter is the largest planet? and wait.

And you can see the sprite here.

There's a speech bubble with that question.

If the answer equals true, then say "Correct!" for two seconds and switch costume to planet.

The user has a box at the bottom to input their answer and if they do answer true, then it will say "Correct!" for two seconds and switch costume.

Or else, so if the player inputs anything other than the word True, it will say "Incorrect!" for two seconds, change colour effect by 170, wait 0.

5 seconds and set colour effect to zero, So you can see that here, if you open the project, have a look.

You've done so well in the first part of the lesson, Programme a quiz.

Let's now move on to the second part of the lesson, Test a quiz.

Jacob and Sam are working on their programmes.

Jacob says, "My programme has lots of different sequences." Sam says, "Are you testing your programme as you go?" Testing means running your programme to see if it does what you expected.

You should test your programme to make sure it runs the correct outcome if the condition is True, but also to see if it has the right outcome if it is False.

Which programme contains "no" as part of its condition? Pause the video and have a little look at the code here.

You've got code A and code B.

See if you can work out which one contains a "no" as part of its condition.

Pause the video to have a go.

Super thinking.

If you look through both codes, code A says, when green flag clicked, say, Welcome to my quiz for two seconds.

Ask is Madrid the capital of Belgium? and wait.

If the answer equals no, then change colour effect by 50 or else say Wrong for two seconds.

My condition is, is the answer "no"? True or False? And that's because Madrid is not the capital of Belgium.

This programme contains "no" as part of its condition.

In code B, we've got when green flag clicked, say Welcome to my quiz for two seconds.

Ask is Paris the capital of France? and wait.

If answer equals yes, then say Well done! for two seconds, or else move 10 steps.

My condition is, is the answer "yes" True or False? And that's because Paris is the capital of France.

This one does not contain the word "no" as part of its condition.

Do you remember what finding and fixing mistakes in a programme is called? Andeep says, "Finding and fixing errors in code is called debugging.

You should test your programme often to spot bugs." Test your first question and answer coding sequence.

Run your programme, type the correct answer.

Jacob says, "I ran my programme and it prompted me to input an answer." What happens? Jacob says, "I put in the correct answer and the True outcome sequence happened." Does the right outcome happen? Jacob says, "This time I put the wrong answer in to test the False outcome." Hopefully Jacob will get the right outcome if he puts the wrong answer in.

Test your programme often as you go.

Don't wait until the end.

You may find you need to make some changes to your design as you code, and that is fine.

Programmers write code in different ways, but your programme should still contain the concepts from your design.

That means you might need to make some changes as you go, but you don't want to completely move away from your design template.

Fantastic thinking.

I've got a question here for you.

True or false? You should only test your programme when you are completely finished with coding it.

Pause the video and have a quick think.

Is that true or false.

The answer is false, and why is that? You should test your programme often as you go.

This will help you pick up mistakes and make it easier to debug your programme.

Test a quiz.

Once your first question and answer sequence is working correctly, you can add your second question.

Here's the example of my branching algorithm.

We've got the start.

Ask the user: The third planet from the sun is.

? If the answer equals Earth and I'm going to follow the True arrow in my branching algorithm, then say, "Well done!" and play space sound.

Or else, if it's false, and I'm going to follow the false arrow, say "That's not it!" and play a "no" sound.

If the output from your programme doesn't matter your algorithm, you should check these things.

Have you used the if, then, else structure for selection? Have you included the correct answer as part of your condition? Have you spelled the answer correctly in your condition? So that means, if for example, your question is: Which planet is the largest in the solar system? And if you've misspelt that yourself in your condition, then your player won't be able to input the correct answer.

So you've got to also check your own spelling.

Have you placed the command blocks for the True outcome in the "then" section of the selection command block? Have you placed a command blocks for the False outcome in the "else" section of the selection command block? Sam says, "Be careful where you place your blocks.

It's easy to accidentally place a sequence in the wrong place." Let's take a little look at these blocks here in Scratch.

When this sprite clicked, ask: True or false? Jupiter is the largest planet.

and then wait.

If answer equals true, then say "Correct!" for two seconds, switch costume to planet.

Or else say "Incorrect!" for two seconds.

Change colour effect by 170.

Wait 0.

5 seconds.

Set colour effect to zero.

Ask the third planet from the sun is.

? and wait.

If answer equals Earth, then.

Something's gone wrong here in the sequence.

It looks as if I put the coding for my next question ask the third planet from the sun is.

? and wait.

If answer equals Earth, then I've put all of that within the "else" answer from my previous question.

That's not right.

It's not where it should go.

You can fix a mistake by right clicking on the coding workspace and selecting Undo.

Your second sequence should go underneath the first question and answer.

That looks much better.

Well done.

You've done so well.

And I've got a task here for you.

I'd like you to complete two or more question and answer sequences.

For each sequence, test and record: run your programme, type the correct answer.

What happens? Try a wrong answer.

Does the right outcome happen? Pause the video to finish the task.

I've got some feedback for you.

I'd like you to open a project on oak.

link/solar-system-2.

Take a listen and look at the code for both questions.

We've got when this sprite clicked, ask true or false? Jupiter is the largest planet and wait.

If answer equals true, then say "Correct!" for two seconds, switch costume to planet.

Or else say "Incorrect!" for two seconds.

Change colour effect by 170.

Wait 0.

5 seconds and set colour effect to zero.

Ask the third planet from the sun is.

? and wait.

If the answer equals Earth, then start sound "space fly by." Say "Well done!" for two seconds or else start sound, "head shake." Say, "That's not it!" for two seconds.

Let's take a look at what I've tested and recorded.

Run your programme.

I'll put a tick for that.

I did that and checked it.

Typed the correct answer.

I did that and checked.

What happens? I got the correct outcome.

Then try a wrong answer.

I did that and checked it.

Does the right outcome happen? Yes, I got the outcome for the false.

Well done, you've done so well in today's lesson, Programme a Quiz.

Let's summarise.

In this lesson, a question-and-answer quiz programme was created.

Starting from a branching algorithm quiz design, conditions were used to build selection structures such as if, then, else structures.

The sequence was tested by entering correct and incorrect responses to check whether the outcomes matched the original design.