Hi all,
I have this code and function that is intended to be put into the head section of a page, but I want to break it up and have it as a function in my separet tools.js page and call it ONLY when i need to, rather than having all of this code in my HEAD tag.
var theImages = new Array()
theImages[0] = ‘../images/randomimages/1.jpg’
theImages[1] = ‘../images/randomimages/2.jpg’
var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write(‘<img src=”‘+theImages[whichImage]+'”>’);
}
Can someone be kind enough to break it up so that it would work as a separate function called?
I think the bit I am missing is the ‘return’ bit at the end – is this correct?
Kind regards