JavaScript : Creating a Random Quiz
Contents ]
Dr Benton

Saving Questions

Storing our questions and answers is handled directly by the JavaScript code. For this purpose we make intensive use of arrays.

49: <SCRIPT LANGUAGE="Javascript">
50:
51: Vignts = new Array("img01.jpg", "img02.jpg", "img03.jpg", "img04.jpg", "img05.jpg", "img06.jpg")
52: Choix1 = new Array("Texas Instrument TI99", "Amstrad CPC 6128", "Dragon 32", "Matra Alice 90", "Apple Macintosh SE", "Atari 600 XL")
53: Choix2 = new Array("Amstrad CPC 464", "Atari 800", "Apple IIe", "Apple IIe", "Apple I", "Atari 130 XE")
54: Choix3 = new Array("Sinclair Spectrum", "Mattel Aquarius", "Apple IIc", "Commodore Vic-20", "Sinclair ZX81", "Commodore 64")
55: Repons = new Array(1, 0, 2, 1, 0, 1, 2, 1, 0, 2, 1, 0, 1, 2, 1)

Five arrays are a must.

  • Vignts (line 51) contains the names of all thumbnail images.

  • Questions are unique and you must have more images than questions.

  • Choix1, Choix2 and Choix3 (lines 52, 53 and 54) contain the list of all the possible computers which appear as the first, second and third items in the drop-down lists.

  • Repons (line 55) holds the number of the correct answer for each of the choices submitted.



  1   2   3   4   5   6