Alert(t); // to reduce the number of loop

I want to write vakit() instead of setTimeout()

I tried to write a function that displays a message after two seconds.

setTimeout(function(){alert(“after two seconds”)},2000);

The code I write

<script type="text/javascript">

function vakit( vazife, gecikme){

var n =;
var s = n + gecikme;
var t = 0;
for(var i = n; i <= s; ){

if(i==s){ //alert("tamam"); 

vazife();  break;
i =;

} // for bitti


} // vakit fonksiyonu bitti

// vakit fonksiyonunu çağır

vakit(function(){alert("iki saniye sonra")},2000);


t is the number of loop
alert(t); displays 1732055
How can I reduce the number of loop?

var vakit = window.setTimeout;

be aware that your vakit() function is blocking (i.e. no JS will run until the function is done)

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.