i am trying to put together a web site for one of my classes so my students can test themselves on tree identification. i can get the simple code to produce 10 random number and display the 10 images out of an array associated to those 10 numbers. i cannot get the code to work to test whether or not that image has been displayed. basically, i have 15 images (expanding each week and will reach 128 at end of semester) that i want to select 10 images randomly with no repeats. any suggestions on how to test for this would be great. ive tried using a for loop to test but i cannot figure out how to make it check the re-calculation of the random number.
var theImages = new Array()
theImages[0] = ‘1_1.jpg’
…
theImages[14] = ‘1_15.jpg’
var s = 0;
var p = theImages.length;
var preBuffer = new Array();
var theTest = new Array(10);
for (i = 0; i < p; i++){
preBuffer[i] = new Image();
preBuffer[i].src = theImages[i];
}
function showImage(){
for (j = 0; j < 10; j++){
var whichImage = Math.round(Math.random()*(p-1));
theTest[j] = whichImage;
s = 0;
for (t = 0; t < 10; t++){
if (theTest[j] == theTest[s]){
whichImage == Math.round(Math.random()(p-1));
}
else{
s = (s + 1)
}
}
document.write(‘<img src=”‘+theImages[whichImage]+'”><br><hr>’);
}
}