- Learnt28 min · delete, insert, replace, delete all
- Basic24 min · the ones you get right leave
- Challenge 1–327 min · a bonus, a typo, a fresh game
- Extrabonus · your own revision list
Review — where we got to 5 min
add [thing] to [questions v]puts a row on the end.(item (3) of [questions v])reads a row back. Rows start at 1.(length of [questions v])drives a loop of any size.
Quick-fire
Your list has 4 rows. What does (item (5) of [questions v]) give you?
Reveal the answer
Nothing at all — an empty answer, and no error message. That silence is what makes an off-by-one in a list so hard to spot.
Today’s Topic 3 min
delete (1) of [questions v]— and what it does to the row numbersinsert [thing] at (2) of [questions v]— pushing the rest downreplace item (2) of [questions v] with [thing]— swapping in placedelete all of [questions v]— starting over
Learning outcome
By the end of this lesson you will be able to:
- Take a row out of a list and explain what happened to the rows below it.
- Choose between insert and replace, and say why.
- Build a game where the list is the state — what is left is what is left to do.
Learnt — taking things out and putting things in 28 min
1 · Delete, and the thing nobody expects
Variables has a block that takes one row out:
delete (1) of [questions v]
Here is the part that catches everybody. The list does not leave a gap — everything below moves up a row. So the question that was item 2 a second ago is item 1 now, and the numbers you were holding in your head are all wrong.
How to use this: Click the green flag and watch the box on the left when row 1 disappears.
2 · Insert pushes the rest down
insert [BONUS: how many days in a week?] at (2) of [questions v]
3 · Replace swaps one row
replace item (1) of [questions v] with [What colour is a lemon?]
| Block | Rows below | Length |
|---|---|---|
delete (2) of [questions v] | move up | one shorter |
insert [q] at (2) of [questions v] | move down | one longer |
replace item (2) of [questions v] with [q] | do not move | the same |
How to use this: Click the green flag and watch the box: first an insert, then a replace. Count the rows each time.
4 · Delete all, and starting again
You met this one last lesson as the block that stops your quiz doubling in size. It is also how you start a second game without pressing the green flag:
when [r v] key pressed
delete all of [questions v]
add [What colour is a banana?] to [questions v]
add [How many legs has a spider?] to [questions v]
Basic — the ones you get right leave 24 min
Open your quiz. You are going to change what the list means: from “all the questions” to “the questions you still have not got right”.
Step 1 — always ask row 1
- Find your loop and take the counter out of it.
- Change the say to
(item (1) of [questions v]). - Run it. It asks the same question for ever — that is expected.
Step 2 — a right answer removes it
- After the question, add
ask [Your answer?] and wait. - In the right-answer half, add
delete (1) of [questions v]. - In the wrong half, do nothing to the list.
Step 3 — a wrong answer sends it to the back
- In the wrong half, add the question to the end with
add (item (1) of [questions v]) to [questions v]. - Then
delete (1) of [questions v]. - Now a missed question comes round again, at the back of the queue.
Step 4 — stop when the box is empty
- Wrap the lot in
repeat until <(length of [questions v]) = (0)>. - After it, say something triumphant.
Step 5 — show your working
- Make sure the list box is ticked so it shows on the Stage.
- Play a round and watch the rows disappear as you get them right.
repeat until <(length of [questions v]) = (0)>
say (item (1) of [questions v]) for (1.5) seconds
ask [Your answer?] and wait
if <(answer) = (item (1) of [answers v])> then
say [Right - that one is done.] for (1) seconds
delete (1) of [questions v]
delete (1) of [answers v]
else
say [Not quite. It will come round again.] for (1) seconds
end
end
say [All of them, finally!] for (3) seconds
How to use this: Click the green flag and watch three rounds go by. Each right answer takes a row out of the box.
The quiz asks the same question for ever.
Nothing is being deleted. Check the delete block is inside the right-answer half and that it is deleting row 1.
The answers stop matching the questions after one round.
You deleted from questions but not from answers. Two lists kept in step have to shrink together.
The loop never ends even though the box looks empty.
The repeat until is testing the wrong list, or comparing to something other than 0. Tick both list boxes and watch which one still has rows.
A missed question never comes back.
The add block has to run before the delete, or you are adding a row that has already gone.
A bonus question, mid-game
Drop a surprise question in, without disturbing the ones already answered.
- After two questions, a bonus appears next in the queue.
- The questions still to come keep their order.
- The ones already done are not asked again.
How to use this: Click the green flag. Two questions, then the bonus is inserted — watch the box.
Teacher note
Insert at ((n) + (1)) rather than at a typed row number — the whole point is that the bonus goes in front of whatever is next, wherever the player has got to.
Fix the typo
One of your questions has a spelling mistake. Fix it without restarting the quiz.
- Find the row with the typo in it.
- Correct it in place.
- The list is the same length afterwards, and nothing moved.
How to use this: Click the green flag and watch row 4 — the wrong spelling, then the right one.
Teacher reveal — why not delete and add?
replace item (4) of [questions v] with [What do cows drink?]
Because delete then add puts it on the bottom, and if the answers list has not moved too, question 4 now has question 4’s old answer. This is the cheapest possible demonstration of why the right block matters.
Play again
Let the player start a fresh game without touching the green flag.
- R empties the list and stocks it up again.
- A counter says which game this is.
- The old questions do not come back twice over.
How to use this: Click the green flag, then click the stage once. Three questions drain away — then press R.
Teacher reveal
when [r v] key pressed
change [plays v] by (1)
delete all of [questions v]
add [What colour is a banana?] to [questions v]
add [How many legs has a spider?] to [questions v]
say (join [Game ] (join (plays) [. All five back.])) for (2.5) seconds
This is the same stocking blocks as the green flag, which is a fair prompt for Lesson 3-14: a job done in two places is a job that wants a My Block. Worth planting now, not solving.
Your own revision list
Build a second list as you play, holding only the questions you got wrong. At the end, that list is the thing worth keeping.
- A list called
missed, emptied at the start. - A wrong answer adds that question to it.
- At the end, the host says how many there are to revise.
How to use this: Click the green flag and watch two boxes: the questions going by, and the missed list filling up.
Teacher reveal
when flag clicked
delete all of [missed v]
...
else
say [Missed that one.] for (1) seconds
add (item (n) of [questions v]) to [missed v]
end
The delete all of [missed v] at the top is the same trap as last lesson, on a second list — and pupils who fixed it once still forget it here. Let them press the flag twice.
Summary 5 min
delete (1) of [questions v]takes a row out — and everything below it moves up.insert [q] at (2) of [questions v]pushes the rest down and makes the list longer.replace item (2) of [questions v] with [q]swaps one row and changes nothing else.delete all of [questions v]empties it, ready to stock again.- A list can BE the game state: what is left in the box is what is left to do.
- Delete
- Take one row out. The rows below move up.
- Insert
- Put a row in at a given number. The rows below move down.
- Replace
- Swap what is in one row, leaving the length alone.
- Queue
- A list you always take from the front and add to the back.
Hand in
Save your quiz. Next lesson it stops needing the answer spelled exactly one way — one block will search a whole list of accepted answers for you.