Using lists

Quiz time with Scratch - Lesson 2

Objectives

  • Create programs that implement algorithms to achieve given goals
  • Understand, explain and use lists effectively and relate them to variables

Lesson Resources

Introduction

Recap last week’s lesson, ask the class -

  • what project did we create in the last lesson?
  • What is a variable?
  • What variables did we create and what were they used for in our code?

Take a look at a project from last week and ask the students to talk through how it worked and what new things they learned about in the process. 

Ask them to have a look at this addition project. They can find it by typing this short URL into their browser address bar: goo.gl/3L2LlO (please note it is case sensitive)

It’s more of an interactive calculator than a quiz, but it uses many of the principles covered last week to make it work.

Ask the students to try it out and then study the code with a friend and then ask them to try and explain:

  • how does it work?
  • Are there any parts to the code you haven’t seen before?
  • Can you guess what they do?
  • What do you think a broadcast is?
  • Where is it used and why?

A broadcast is a trigger that can be given a specific name by you. Different triggers can be used to start other bits of script by combining the broadcast block with a ‘when I receive’ block. 

 

 

Ask the class:

  • What are the variables in this project?
  • What is the purpose of the ‘if/else’ block this time?
  • How do the number spinners work?
  • How does it ensure that it will always give you different numbers to add?

 

What is a list?

Today we are going to look at a new concept called a list. Everyone should be familiar with the term in contexts such as shopping lists or ‘to-do lists’ etc, and their use isn’t that different here. A list in Scratch (called an array in other programming languages) is a tool that can be used to store multiple pieces of information at once. It can also be defined as a variable containing multiple other variables. A list consists of numbers paired with items. Each item can be retrieved by its paired number. List blocks can be found in the Data blocks palette (or in ‘Variables’ in Scratch v1.4). 

This project demonstrates a list being used with an ‘ask and wait’ input box so the user can add to the list: 

 

   

 

A list (called ‘Shopping list’) was created in the Data category. The question ‘What do we need from the shops today?’ is asked and then the answer is added to the list. This is then repeated 5 more times with the question ‘What else do we need?’ and each answer in turn is added to the list. At the end, the list as they created it is reported back to the user. Restarting the code with the green flag clears the list out because of the ‘delete all of shopping list’ block at the top of the code. 

Then you can add in a bit of animation to make it more interesting! 

There are lots of functions with list blocks, more than with variables. Some of the blocks have options hidden in the drop down menus, such as these two:

 

With these options you could delete a specific number (you can type any number in the box) from the list, the last item on the list or all the items on the list.

 

With these options you can select a specific number (you can type any number in the box) from the list, the last item on the list or a random selection from the list.

 

 

Your list project

Ask them to have a go at creating their own version of this project that asks the user for their top five pop stars, footballers, songs, subjects at school etc... they can choose.

Here’s an example with a couple of small tweaks from the original shopping list project:

 

 

At this point the students can consider what they would add to this project to improve it. 

They may want to improve the visual side of its design by changing the sprite and perhaps adding costumes or animation to it. They might also add an appropriate background to the stage and other visual or sound effects. 

They can also tweak the code if they have other ideas to add to the project.

 

Plenary

Towards the end of the lesson introduce this memory game project which will be the task in the next lesson. 

They can find it by typing this short URL into their browser address bar: goo.gl/WWCJML (please note it is case sensitive)

Give them a chance to play the game and start to look at some of the code. Ask the class:

  • How do you think lists are used in this project?
  • Is there anything else interesting that you noticed in the project?

 

< Previous Lesson

Next Lesson >