previous

page 4

next

My plan is to set up an array g_ind with values 0 to g_pics.length-1, shuffle that array and use the first 5 entries for the answers.

Then we choose a random id between 0 and 4 as g_answer_id.

So we'll need my library and a new file, globals.js.

my globals.js
var g_n=g_pics.length;
var g_ind=[];
for (var i=0;i<g_n;i++) g_ind.push(i);
var g_answer_id;

leading to ...

setup() in functions.js
function setup() {
Shuffle(g_ind);
g_answer_id=Random0(4);
var pic_n=g_ind[g_answer_id];
var el=document.getElementById('pic');
el.src='images/'+pic_n+'.jpg';
for (var i=0;i<5;i++) {
var el=document.getElementById(i);
var pic_n=g_ind[i];
el.textContent=g_pics[pic_n];
}
}

Check this all works ok.

previous
next