
previous

page 6
next
Asking multiple questions
We'll need to specify how many questions in our quiz and we'll need a counter to keep track.
additions to globals.js
var g_questions=3;
var g_count=0;
var g_count=0;
I set the number of questions to 3 to make testing quicker - we can change it later.
It makes sense to split up setup() like this:
function setup() {
get_pic();
}
function get_pic() {
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];
}
}
get_pic();
}
function get_pic() {
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];
}
}
previous
next