Skip to content
Game 6 Unit 6 of 8 1 hr learning time

Categories

Add category labels in bright colour above each question, mapped from a numeric index in DATA.

75% of Quiz Master

Every question belongs to a category — Science, History, Geography, or Entertainment. The category appears above the question in its own colour, giving each subject a visual identity.

Category Index in DATA

The DATA now starts with a number — the category index:

500 DATA 1,"Closest planet to the Sun?","Mercury","Venus","Earth","Mars","a"

READ p, q$, a$, b$, c$, d$, r$ pulls the index into p before reading the question. p is 1 for Science, 2 for History, 3 for Geography, 4 for Entertainment.

Mapping Index to Name and Colour

 314 REM === Category label ===
 316 LET ci=6
 318 IF p=1 THEN LET m$="Science"
 320 IF p=2 THEN LET m$="History": LET ci=3
 322 IF p=3 THEN LET m$="Geography": LET ci=4
 324 IF p=4 THEN LET m$="Entertainment": LET ci=5
 326 PRINT AT 3,(32-LEN m$)/2; INK ci; BRIGHT 1;m$

Geography category in green above the question

A chain of IF statements maps the number to a name and colour. The name goes into m$ (not c$ — that’s option C). The colour goes into ci. Then PRINT AT centres the name and applies the colour with INK ci; BRIGHT 1.

Each category has its own colour:

  • Science — yellow (INK 6)
  • History — magenta (INK 3)
  • Geography — green (INK 4)
  • Entertainment — cyan (INK 5)

Why Not Store the Name in DATA?

You could store "Science" instead of 1 in the DATA. But numbers are easier to use as array indices — and in the next unit, s(p) will track the score for category p. A number maps directly to an array slot. A string would need a comparison chain every time you want to update the score.

Try This

Fifth category. Add a “Sport” category with index 5 and INK 2 (red). Write two sport questions and update the IF chain.

Category count. After all questions, count how many questions came from each category. You already know the index — just increment a counter.

What You’ve Learnt

  • Numeric index — store a category number in DATA, not a name string
  • Mapping chainIF p = 1 THEN LET m$ = "Science" converts index to display
  • Colour per category — each subject gets its own INK, creating visual identity
  • Centring(32 - LEN m$) / 2 centres the category name