Skip to content
Game 10 Unit 3 of 6 1 hr learning time

Categories

Group the questions into subjects: each category is a section of DATA, reached with RESTORE to a line number, read as a header then its questions.

50% of Quiz Master

A flat list of questions is a quiz; categories make it a game with shape — Animals, Space, History, Geography. The trick is organising the DATA into sections and jumping to the one you want, which is what RESTORE with a line number does.

   5 DIM k(8)
  10 BORDER 0: PAPER 0: INK 7: CLS
  50 RESTORE: FOR i = 1 TO 8: READ k(i): NEXT i
  60 RESTORE 600
  80 LET score = 0: LET n = 0
  90 FOR c = 1 TO 4
 100 READ t$,ink
 110 FOR q = 1 TO 2
 120 LET n = n + 1
 130 CLS
 140 PRINT t$
 190 READ q$,a$,b$,c$,d$
 200 PRINT "Question ";n;" of 8"
 210 PRINT q$
 220 PRINT "1. ";a$
 230 PRINT "2. ";b$
 240 PRINT "3. ";c$
 250 PRINT "4. ";d$
 260 INPUT "Answer (1-4): ";g
 270 IF g = k(n) THEN PRINT "Correct!": LET score = score + 1
 280 IF g <> k(n) THEN PRINT "The answer was ";k(n)
 300 PAUSE 80
 310 NEXT q
 340 NEXT c
 360 PRINT "You scored ";score;" out of 8"
 550 DATA 1,2,3,4,3,2,3,2
 600 DATA "Animals",4
 610 DATA "How many legs does a spider have?","Eight","Six","Ten","Twelve"
 620 DATA "What is the fastest land animal?","Lion","Cheetah","Horse","Wolf"
 630 DATA "Space",5
 640 DATA "Which planet is closest to the Sun?","Venus","Earth","Mercury","Mars"
 650 DATA "How many planets orbit the Sun?","Seven","Nine","Ten","Eight"
 660 DATA "History",2
 670 DATA "In what year was the Moon landing?","1959","1965","1969","1972"
 680 DATA "Which country built the pyramids?","Greece","Egypt","Rome","China"
 690 DATA "Geography",6
 700 DATA "What is the largest ocean?","Atlantic","Indian","Pacific","Arctic"
 710 DATA "What is the capital of France?","London","Paris","Rome","Berlin"
ZX Spectrum Quiz Master: a category name above Question 1 of 8 with four options
Each pair of questions sits under its category, read from its own section of DATA.

RESTORE to a line

Cipher used a bare RESTORE to rewind the DATA to the start. RESTORE 600 is sharper: it moves the read pointer to a specific line, so the answer key can live at line 550 and the questions at 600 onward, read independently. Line 50 reads the eight-entry key (DIM k(8) now); line 60 — RESTORE 600 — then parks the pointer at the questions before play begins. Pointing RESTORE at a line lets one DATA block hold several kinds of content, each section reached on demand.

A loop inside a loop

The round is now two nested loops. The outer FOR c = 1 TO 4 (line 90) steps through the categories; each pass reads a header — READ t$, ink — giving the subject name and its colour. The inner FOR q = 1 TO 2 (line 110) plays that category's two questions. A counter n ticks across all eight so the answer-key index stays right. Nested loops — one for the group, one for the items within it — are how you walk any structure that has sections: chapters and pages, levels and rooms, categories and questions.

Next: dress each question as a proper card.