Maths Quiz Variables Activity

Maths quiz – adding a score activity: Using variables in programs

Recommended Age Group: 7 – 11 years
Activity Duration: 1 hour

Concepts and approaches

  • variables-icon
  • selection-icon
  • programming-icon

Overview

In this activity pupils learn about variables and how they can be used in programs. Pupils learn to use variables in Scratch to make a scoring system for the maths quiz they made in the introduction to selection activity (Use selection in programs – maths quiz).

Pupil objectives

  • I can explain what a variable is
  • I can use variables in a program

Introduction (5 mins)

  • Remind pupils they created a maths quiz in Scratch. Ask pupils if they can recall what type of command they used to get the program to respond to the player and how this worked? Selection Commands
  • Load one of the pupils’ maths quiz files. Run and play the quiz to remind pupils of how it operates.
  • Guide a discussion to determine one improvement for the quiz would by having a scoring system.
  • Explain that in this activity pupils will be adding a scoring system to their maths quiz and to do this they will use variables.

Introducing variables (5 mins)

  • Have pupils heard of the term variable before? Perhaps they heard the term used in other subjects, such as science? What can pupils recall about a variable in science? It is something we change.
  • Depending on pupils’ existing understanding, use slide 3 to briefly explain the concept of variables, covering the following points:
    • Variables are one way in which computer programs can use part of a computer’s memory to store, retrieve or change simple data, such as numbers.
    • We can think of a variable as a box within our program that we can place data in. We can then use the data when we need it within our program. The data in the variable might change as our program runs.
    • We can look to see what the data in our variable is at any time.

Introducing variables in Scratch (10 mins)

  • If any pupils know how to create a variable in Scratch let them demonstrate to the class, as shown in screenshot below.
Variables_image 2_Create variable 1.4

Creating a variable in Scratch 1.4

Variables_image 3_Create variables 2

Creating a variable in Scratch 2

  • Discuss with pupils the importance of using logical names for our variables so we know what they are for when coding.
  • Highlight that once we have created the variable ‘score’ this now appears within the stage area, as shown below.
Variables_image 4_stage

Once you have created a variable it is displayed in the stage area with its value.

  • Show pupils the list of commands which now appear within the variables tab, as shown below. Lead a short discussion with pupils on what they think the commands might do?
Variables_image 5_variable commands

The commands available within Scratch which can be used to manipulate variables.

  • Ask pupils how they think the commands could be used in the maths quiz. Add that you aren’t going to show exactly how to use these commands as this will be pupils’ challenge shortly.
  • Explain to pupils that the process above can be repeated to create another variable. For example, we might want to have a ‘Lives’ variable that changes during the quiz also.

Main task: Pupils create their scoring system (30 mins)

  • Ask pupils to open their maths quizzes. For any pupils who do not have a maths quiz demonstrate how to open the example maths quiz from your school network or by accessing it online: maths quiz example.
  • Pupil task (5 mins): Give pairs 5 mins to run their maths quiz and explain to other how their program works to recap the previous activity. Write the following questions up to guide pupils’ discussion during this time:
  • Can you explain to your partner:
    • The overall algorithm on which your program is based?
    • What each command in your program does?
    • Why you have used each command?
    • Which is a selection command?
    • How the selection command works?
    • Why the selection command requires a condition? What condition have you used?
    • What happens when the condition is/is not met?
  • Pupil task (5 mins): Before pupils add the scoring system they need to design it,create the rules to say how it will work. Ask pupils if they can remember what we call a rule that makes something happen? (algorithm). Pupils have 5 minutes to make notes describing how they want their scoring system for their quiz to work. Slide 4 provides prompts for pupils to consider during this activity.
  • Ask a selection of pupils to feedback to the class their scoring system design.
  • Pupil task (5 mins): Pupils are given time in pairs to add their scoring system to their maths quiz. Slide 5 & 6 (depending on the version of Scratch you are using) of the presentation can be displayed to remind pupils of how to create a variable during this task.
  • Provide support to pupils who require it. A Scratch commands help sheet has been included with this activity.
  • Remind pupils that it can be useful to run their program as they are writing it to check it does as they expect and matches their algorithm design.
  • Mini-plenary on initialisation (5 mins): Ask the following questions in order to guide a brief discussion around initialisation:
    • Who’s managed to get their variables changing in value in their quiz? Does anything strange happen when you play the quiz again and again? Some pupils variables will continue with the values they ended with when the program was last run.
    • Can anyone think what we might need to do at the beginning of our program if this is happening? What commands could we use for this? Set the initial values for our variables using ‘Set variable to’.
  • If pupils complete the main task an extension has been provided, see below.

Extension

  • A Scratch maths quiz extension file encourages pupils to tinker with a more complex use of variables. Pupils explore a quiz that ends if the player runs out of lives. Pupils could be asked to add comments to this file, to explain how the code works and how variables are used. They could tinker with the code which changes the variables and see how this changes the game when it is played. Pupils can then share what they found out either with another pair or with the whole class.

Plenary (10 mins)

  • Pupils they will now get the opportunity to play each other’s’ maths quizzes and as they do so they will use logical reasoning to work out how the game has been programmed.
    • Play the quiz in full screen mode.
    • Make a prediction about the variables and code used to alter the variable values based on their experience in playing the quiz, e.g. I think you’ve added a variable called ‘playerscore’ and when I get the answer right the score goes up by 2. You’ve done this using a ‘Change score by 2’ in the if … then block…
    • Check their predictions with the program’s code to see if they are correct.
  • Finally, use the questions on slide 7 to guide a discussion.

Differentiation

Support

  • An additional adult, if available, may work with a small group of pupils to provide additional support when required. The Scratch commands help sheet can also be provided to those pupils that require it during the main tasks.
Stretch & Challenge

  • An extension activity has been provided above for pupils completing the main task.

Assessment opportunities

  • Informal teacher assessment of during main task, class discussions and plenary.
  • Formal summative assessment of Scratch projects.
  • Focus of assessment on understanding on what a variable is, and how it can be used in a program. This is evidenced by their use of code to alter their scoring variables.

Teaching Notes

Concepts and approaches

  • In this activity pupils use variables to keep track of the score in their maths quiz program.
  • Pupils use selection in their programs to execute different code depending on whether the player answers the quiz questions correctly or not.
  • In this activity pupils are adding to the maths quiz program they created in Use selection in programs – maths quiz

Curriculum links

For links to the primary curriculum in your country, please refer to the relevant download below.

Resources

  • MIT’s Scratch 2.0 or Scratch 1.4. (Please refer to this guide and use our Scratch resources in your school).
  • Pupil access to the maths quiz programs pupils created in Use selection in programs maths quiz. For pupils without access to their maths quiz, use the example Scratch file (see download link at bottom of webpage) or Scratch 2 version online at example maths quiz.
  • Maths quiz score presentation (see download link at bottom of webpage).
  • Scratch commands help sheet – Up to one per pair if required (see download link at bottom of webpage).
  • Extension sheet – Up to one per pair if required (see download link at bottom of webpage).
  • Maths quiz extension Scratch file (see download link at bottom of webpage) or Scratch 2 version online at maths quiz extension

Taking this further

Pupils could use their experience from this activity to make quizzes for a range of subjects from across the curriculum. The variable ‘answer’, which stores the user’s response to the ‘Ask….. and wait’ command, can store both text as well as number data, meaning pupils’ questions could ask for text responses, such as the names of countries in geography for example. Pupils aged 7 – 11 years could create quizzes to support the learning of pupils aged 5 – 7.

Variables could also be used to alter the questions asked. For example a user might be asked if they want an easy or hard quiz. A variable easy_or_hard_indicator could be set according the user’s response. Then within the program an IF… THEN…selection uses the variable to control the complexity of the quiz.

Pupils aged 7 – 11 years could create quizzes to help younger pupils revise their learning. By hosting the quizzes pupils create on the school network they can be used across the school. Alternatively, by uploading pupils’ quizzes to the Scratch 2 online community (http://scratch.mit.edu) they can be posted on or embedded in your school’s website or blog for others to play. In order to do this you or your pupils (with parental permission) would need to sign up for a Scratch community account, which is free.

Downloads

England

Wales

Scotland

Northern Ireland