Re-written twice. Once with comments and once without.
You need to pick up on the use of brackets{} and semi-colons; especially when starting out.
I know these older tutorials seem to have omitted this syntax.
I’ve made a few simple changes, but tried to keep close to the original.
I would say eval should only be used when you really know what you’re doing and in special circumstances. Genarally there’s an alternative.
step++ just means add 1. could be written step += 1 or step = step + 1.
the setTimeout doesn need to have slideit() in quotes. As you are not passing parameters to the function just the name will suffice.
if you do need to pass parameters/arguments you can do it like this and use an anonymous function.
setTimeout( function(){ slideit(‘a’, ‘b’, 3 ); }, 2500 );
It takes a bit of time to grasp this stuff. I know.
Really you need to try and find some more up to date tutorials. There is a course that is part of this site ‘JavaScript Programming for the Web’, which is possibly worth looking into. https://learnable.com/sitepoint?utm_source=sitepoint&utm_medium=channel&utm_campaign=sitepoint
//variable that will increment through the images
var step=1,
// Alternative shortand. images = [ firstcar, secondcar, thirdcar ]
images = new Array( firstcar, secondcar, thirdcar ),
numOfImages = images.length; // 3
function slideit(){
//if browser does not support the image object, exit.
if (!document.images) { return }
document.images.slide.src = images[step] + '.gif';
if (step < numOfImages) { // is step smaller than the number of images?
step++; // yes, then step = step + 1. can be shortened to step += 1.
} else {
step = 1; // if not i.e. in this case 4. reset step.
}
//No need for 'slideit()'. slideit will do here.
setTimeout(slideit, 2500);
}
slideit();
// Less comments so it's clearer where to use brackets { statement block } and semi-colons;
// variable definitions are split by commas and end in a semi-colon;
// e.g. var a = 1, b = 2, c = 3;
var step=1,
images = new Array( firstcar, secondcar, thirdcar ),
numOfImages = images.length;
function slideit(){
if (!document.images) { return; }
document.images.slide.src = images[step] + '.gif';
if (step < numOfImages) {
step++;
} else {
step = 1;
}
setTimeout(slideit, 2500);
}
slideit();
RLM