$('#start-button').click(function(){
if(power === true)
{
$(this).toggleClass('on');
if(start === true)
{
start = false;
}
else
{
start = true;
alert("hello");
while(count < 20)
{
num = Math.floor(4*Math.random());
simon.push(moves[num]);
soundNums.push(num);
var tempCount = count+1;
var start = 0;
while(tempCount > 0)
{
delayMove(tempCount);
}
var timeDelay;
function delayMove(index) {
timeDelay = setTimeout(move(index), 500);
}
function move(index) {
$(simon[index]).fadeOut(200).fadeIn(200);
(sounds[soundNums[index]]).play();
start++;
tempCount--;
}
count++;
$("p").text(count);
}
}
}
});
So i moved the functions outside and have things I think mostly correct, only problem is now the setTimeout doesn't work. I was hoping this would fix the issue with closures by moving the counting variable into the delayed function.