Year 7 · Y7.2 Programming Essentials in Scratch · Lesson 2
Stretch tasks Selection and variables
Quiz Challenge
A quiz game against four computer players, then short and long written answers.
- Quiz Blitz12 questions against the clock
- Quick Fire4 short answers
- Big Think2 long answers
About 20 minutes
This or That
Pixel the cat asks 8 questions. Each has two answers: pick the right one.
- Two answers to every question
- A fish treat for every right answer
- Streaks win Pixel shades, then a party hat
About 4 minutes
Memory Match
Flip the cards two at a time to match each term card to its meaning card.
- 12 cards: each term has a meaning
- One peek at every card
- Combo points for pairs found in a row
6 pairs, about 4 minutes
The games need JavaScript. Every question is below, with the answers at the end.
Read the lesson: Selection and variables
Selection and variables: the questions
Quiz Challenge, round 1: Quiz Blitz
What does selection mean?
- The program runs its steps in order
- The program stores a value
- The program chooses what to do based on a condition
- The program repeats the same steps
score is 12. What does the sprite say?
if <score > 10> then say "You win!" else say "Keep going"- Keep going
- You win! then Keep going
- Nothing
- You win!
score is exactly 10. What does the sprite say?
if <score > 10> then say "You win!" else say "Keep going"- You win!
- You win! then Keep going
- Nothing
- Keep going
In an if ... else block, the if path and the else path can both run.
- True
- False
Which of these is a condition?
- say Hello!
- set score to 0
- touching edge?
- move 10 steps
What is a variable?
- A question with a yes or no answer
- A picture of a sprite
- A named box that stores a value that can change
- A block that repeats forever
What is score at the end?
set score to 0 change score by 1 change score by 1 change score by 5- 1
- 0
- 7
- 5
What is lives at the end?
set lives to 3 change lives by -1 change lives by -1- -2
- 5
- 1
- 3
When you play a game again, it keeps the score from the last game. What is the most likely bug?
- The sprite is too big
- The background is the wrong colour
- The game has too many sprites
- score is not set to 0 when the green flag is clicked
Which THREE are good uses for a variable in a game?
Tick 3.
- Timer
- The green flag
- The stage
- Score
- Lives
Which word means the program chooses what to do based on a condition? One word.
Put the blocks in order: give the player 3 lives, then lose one, then show the lives left.
Number these 1 to 4.
- say lives for 2 seconds
- when green flag clicked
- set lives to 3
- change lives by -1
Quiz Challenge, round 2: Quick Fire
Explain what an if ... else block does. [2 marks]
Give two examples of conditions you might use in a Scratch game. [2 marks]
What is a variable, and why are variables useful in games? [2 marks]
Explain why you should set score to 0 when the green flag is clicked. [2 marks]
Quiz Challenge, round 3: Big Think
A Scratch game should say You win! when the score is more than 10, and Keep going otherwise. Explain how selection and a variable make this work. [4 marks]
Explain how selection and variables could be used together in a simple Scratch game. Give examples. [6 marks]
This or That: tick the right answer
score is 15. Do the blocks inside if <score > 10> run?
- Yes
- No
In an if ... else block, how many paths run?
- Exactly one
- Two at once
What does change score by 1 do?
- Adds 1 to score
- Sets score to 1
Which of these could go inside an if block as its condition?
- move 10 steps
- key space pressed?
lives is 3. What is it after change lives by -1?
- -1
- 2
Your score carries over from the last game. What did you forget?
- set score to 0 at the start
- change score by 1 at the end
Is score > 10 true when score is exactly 10?
- Yes
- No
Which is the better name for a variable that counts lives?
- x
- lives
Memory Match: match each term to its meaning
| Term | Meaning |
|---|---|
| A Selection | 1 A question with a yes or no answer |
| B Condition | 2 Adds 1 to the score |
| C Variable | 3 The program chooses what to do |
D set score to 0 | 4 Runs one of two paths |
E change score by 1 | 5 Puts 0 into the score |
F if ... else | 6 A named box that stores a value |
Answers
Round 1: Quiz Blitz
- The program chooses what to do based on a condition Selection means choosing. Repeating is iteration, and running in order is sequence.
- You win! 12 is greater than 10, so the condition is true and only the first message is said.
- Keep going 10 is not greater than 10, so the condition is false and the else path runs.
- False Only one path runs: the if path when the condition is true, the else path when it is false.
- touching edge? A condition is a question with a yes or no answer.
- A named box that stores a value that can change Variables store values such as score, lives or a timer.
- 7 0 + 1 + 1 + 5 = 7.
- 1 3 - 1 - 1 = 1. Changing by a negative number takes away.
- score is not set to 0 when the green flag is clicked Set your variables at the start, or they carry over from the last game.
- Score; Lives; Timer Score, lives and timers change while the game runs, so they are stored in variables.
- selection Selection: if ... then ... else.
- when green flag clicked → set lives to 3 → change lives by -1 → say lives for 2 seconds Start with the event, set the variable, change it, then show it.
Round 2: Quick Fire
- It checks a condition
- It runs one path when true and the other when false, so only one runs
Model answerIt checks a condition. If the condition is true it runs the first path, and if it is false it runs the else path, so only one of them runs.
- Touching the edge, a colour or another sprite
- A key being pressed
- Comparing a variable, such as score greater than 10
- Checking an answer, such as answer = blue
Model answertouching edge? and key space pressed?
- A named box that stores a value
- The value can change while the game runs, such as score or lives
Model answerA variable is a named box that stores a value. It is useful because the value can change while the game runs, such as the score or the number of lives.
- Otherwise the score carries over from the last game
- So every new game starts from zero
Model answerOtherwise the score carries over from the last game. Setting it at the start resets it, so every new game begins from zero.
Round 3: Big Think
- The score is stored in a variable
- The variable changes during the game, such as change score by 1
- An if ... else block checks the condition score > 10
- If the condition is true one message is said, if false the other
- Only one of the two messages is ever said
- The score is set to 0 at the start
Model answerThe score is stored in a variable, which is set to 0 at the start of the game and changes each time the player scores. An if ... else block checks the condition score > 10. If the condition is true, the sprite says You win!. If it is false, the else path runs and the sprite says Keep going. Only one of the two messages is ever said.
- A variable stores something such as the score or lives
- The variable is set at the start
- The variable changes during the game
- Selection checks a condition
- An example condition, such as touching an enemy or the edge
- A different outcome, such as losing a life or game over
- The variable is used in a condition, such as if lives = 0
Model answerA variable called lives stores how many lives the player has. It is set to 3 at the start of the game. Each time the sprite is touching an enemy, an if block checks the condition and changes lives by -1, so the player loses a life. Another if checks whether lives = 0, and if it is true the game says Game over. A score variable could go up each time a coin is collected, and if score > 10 the sprite says You win.
This or That
- Yes 15 is greater than 10, so the condition is true and the blocks inside run.
- Exactly one Only one path runs: the if path when the condition is true, the else path when it is false.
- Adds 1 to score change adds to the value already there. set replaces it.
- key space pressed? A condition is a question with a yes or no answer.
- 2 Changing by -1 takes one away: 3 - 1 = 2.
- set score to 0 at the start Set your variables when the green flag is clicked.
- No 10 is not greater than 10. It is equal to it.
- lives A name that says what it holds makes the program much easier to read.
Memory Match
- A 3 Selection: The program chooses what to do
- B 1 Condition: A question with a yes or no answer
- C 6 Variable: A named box that stores a value
- D 5
set score to 0: Puts 0 into the score - E 2
change score by 1: Adds 1 to the score - F 4
if ... else: Runs one of two paths