Question

I'm trying to get an answer to another question and hoping adding a functioning JSFiddle will get me some responses. I'm working on the fiddle here:

JSFiddle

But it is giving me errors and not executing despite actually running on my site.

When I run JSHint, it tells me I am missing a semicolon in the first line of my JS, which is not the case.

The two external files are accessible, I can click on them and they pop right up in the browser.

The console on the JSFiddle page returns this 500 internal server error:

GET http://jobs.jsfiddle.net/random.js?callback=Request.JSONP.request_map.request_0 500 (Internal Server Error) moo-clientcide-1.3.js?jobofferinsidebar:3146
inserters.bottom moo-clientcide-1.3.js?jobofferinsidebar:3146
Element.implement.inject moo-clientcide-1.3.js?jobofferinsidebar:3409
Request.JSONP.Class.send moo-clientcide-1.3.js?jobofferinsidebar:12590
wrapper.extend.$owner moo-clientcide-1.3.js?jobofferinsidebar:3798
Class.showJobs Sidebar.js?jobofferinsidebar:60
wrapper.extend.$owner moo-clientcide-1.3.js?jobofferinsidebar:3798
Class.initialize Sidebar.js?jobofferinsidebar:34
(anonymous function) moo-clientcide-1.3.js?jobofferinsidebar:5865
wrapper.extend.$owner moo-clientcide-1.3.js?jobofferinsidebar:3798
(anonymous function) moo-clientcide-1.3.js?jobofferinsidebar:3756
Layout.render LayoutCM.js?jobofferinsidebar:49
(anonymous function) (index):111
(anonymous function) moo-clientcide-1.3.js?jobofferinsidebar:4624
(anonymous function) moo-clientcide-1.3.js?jobofferinsidebar:212
Array.implement.each moo-clientcide-1.3.js?jobofferinsidebar:329
invoke.fireEvent moo-clientcide-1.3.js?jobofferinsidebar:4622
domready

which looks to me like a jsfiddle problem. This is the js code, but I'm pretty sure it's OK.

var i = 0;
var image_slide = new Array('image-1','image-2','image-3');
var NumOfImages = image_slide.length;
var wait = 8000;

function SwapImage(x,y) {       
    $(image_slide[x]).appear({ duration: 1 });
    $(image_slide[y]).fade({duration: 1});
}

function StartSlideShow() {
    play = setInterval('Play()',wait);  
}

function Play() {
    var imageShow, imageHide;

    imageShow = i+1;
    imageHide = i;

    if (imageShow == NumOfImages) {
        SwapImage(0,imageHide); 
        i = 0;                  
    } else {
        SwapImage(imageShow,imageHide);         
        i++;
    }
}

any idea why this would not be executing?

Was it helpful?

Solution

play = setInterval('Play()',wait);

You should pass a function for the first parameter in setInterval()

play = setInterval(Play,wait);

Here is the fixed Demo.

OTHER TIPS

Just remove the quotes around Play() in StartSlideShow function : http://jsfiddle.net/jb8Nx/1/

function StartSlideShow() {
    play = setInterval(Play(),wait);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top