AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Scores and sums

Week 24 · Unit 10: Be a game developer · 3 lessons
2

A quiz that keeps score

Computing 5: Unit 10, pp. 129–144
GoalFollow an algorithm for a quiz that adds points for a right answer and takes points away for a wrong one.
New words
score · a variable that keeps count of the points in a gameanswer · the Scratch reporter that holds what the player typedask and wait · a Scratch block that shows a question and waits for a typed replystart value · the number that a variable is given when the program begins
Explanation

A quiz game needs a variable for the score. When the green flag is clicked, the program first sets the score to its start value. Then it asks a question and waits. What the player types is held in the reporter answer. An if … then … else block compares the answer with the right one: when they match, the score goes up, and when they do not match, it goes down. In Scratch you can write set score to (score + 3), or use the block change score by 3. Both give the same result, and Scratch ignores capital letters in this test.

RuleValue
start value5 points
right answer+3 points
wrong answer−2 points
Worked examples
StepInstruction
1Start when the green flag is clicked
2Set score to 5
3Ask: ‘How many legs has a spider?’ and wait
4If answer = 8, then set score to score + 3 and say ‘Right!’
5Else set score to score − 2 and say ‘Not quite’
6End
This is the algorithm for a Parrot that asks how many legs a spider has. The right answer is 8. If the player types 8, the score changes from 5 to 8. If the player types 6, the score changes from 5 to 3.
Parrotwhenclickedsetscoreto5askHow many legs has a spider?and waitsetscoretoscore+3sayRight!for2secondssetscoretoscore-2sayNot quitefor2secondsifanswer=8thenelse
Here is the same algorithm in Scratch. The condition is the equal-to block. Each path changes the score in a different way.
AfterResultCalculationScore
start5
question 1right5 + 38
question 2wrong8 − 26
With two questions, the score carries on from one question to the next. The player is right on question 1 and wrong on question 2. Each row starts from the score of the row above.
Class activity

Paper quiz master (3 players, paper and a pencil). The quiz master reads out 6 easy questions from a list. One player answers. The score keeper writes the start value 5 on a card and then changes it after each answer: add 3 for a right answer and take away 2 for a wrong one. Write a new value on a new line each time. What is the final score? Now change the rule to +4 and −1. Does the same set of answers give a higher score? (If you have a computer or tablet, build the Parrot program in Scratch.)

Practice
1
The Tortoise starts with 10 points. The player types 8. What is the score at the end? What would it be if the player typed 9?
Tortoisewhenclickedsetpointsto10askWhat is 6 + 3?and waitchangepointsby4changepointsby-3ifanswer=9thenelse
2
A quiz starts at 5 points, adds 3 for a right answer and takes 2 away for a wrong answer. The player is right, wrong, wrong. What is the final score?
AfterResultScore
start5
question 1right?
question 2wrong?
question 3wrong?
3
Why does the program set the score to a start value when the green flag is clicked?
4
A player gives a wrong answer but the score goes up. Which block must be changed, and to what?
Quizwhenclickedsetpointsto5askHow many sides has a hexagon?and waitchangepointsby2changepointsby2ifanswer=6thenelse