Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is setTimeout executing immediately? [duplicate]

I have a simple JavaScript setTimeout function, but it is refusing to work

setTimeout(timeup(tc,chosen),10000)

... and this is the function:

timeup = function (clt,clo)
{   
    alert("time up")
}

... and the time up alert shows up immediately instead of after 10 seconds can someone tell me why this is happening please?

like image 886
Black 'n' Blue Avatar asked Dec 01 '22 19:12

Black 'n' Blue


1 Answers

because you're actually calling the timeup(tc,chosen) function inside the setTimeout function.

try:

setTimeout(function(){
  timeup(tc,chosen);
}, 10000);  
like image 126
nebulae Avatar answered Dec 04 '22 10:12

nebulae