I've encountered an issue with the setTimeout()
function. Take a look at my code snippet below:
$('#start').click(function(event) {
var result = Math.floor(Math.random() * (10000 - 4000 + 1)) + 4000; // generates a random value between 4000 and 10000 and stores it in a variable
setTimeout("$('.reflex').css('background','red')",result); // this part works fine
setTimeout(startTimer(),result); //this line runs instantly without delay
});
Do you see the problem? Using a function inside setTimeout seems to bypass the intended time delay and executes immediately.
Any suggestions on how to resolve this?