Using Lists to Store Quiz Questions

Here’s another possible extension to Phil Bagge’s excellent ‘Maths Quiz‘ set of lessons (see this post for previous thoughts)…

The way I’ve taught children to make a quiz is to make a script for one question then duplicate it, replacing the question and answer in each block repeatedly with the new ones until their quiz is finished. Although this is a relatively quick process, the main drawback to doing it this way is that it produces a very long program and, because most of the script is repeated, this makes it inefficient. It’s also an issue if children make lots of questions then decide to improve their code with sound effects etc, as the code for every question has to be changed. I’ve been trying to teach children that the most effective solution to a coding problem is often the shortest, so I wondered how I could avoid these issues.

The easiest solution seemed to be to create parallel lists of questions and answers and to change the code so that, after each go, the next question and answer in the list is referenced. The programmer just has to keep adding questions and answers to the lists (making sure the item numbers match up) and the ‘repeat’ will keep going for as many questions as there are in the list.

Here’s the code…

(I unticked the list boxes when playing the game so they weren’t visible):

scratchquizlists

Here’s the game…

 

Leave a Reply