previous

page 15

next
Shuffling the letters

The letters in each colour group have to be shuffled.
It's helpful to have a global variable g_colour_ids. And of course we're going to need a shuffle_letters function.

var g_colour_ids=
[[0,3,12,15],[1,4,7,13],[2,8,11,14]];

Have a go at writing shuffle_letters() yourself.

function shuffle_letters() {
for (var i=0;i<3;i++) {
var arr=g_colour_ids[i];
var letters=[];
for (var j=0;j<4;j++) {
var id=arr[j];
var element=document.getElementById(id);
letters[j]=element.textContent;
}
Shuffle(letters);
for (var j=0;j<4;j++) {
var id=arr[j];
var element=document.getElementById(id);
element.textContent=letters[j];
}
}
}
previous
next