<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>setTimeout</title>
</head>
<body>
<script language="Javascript">
var counter = 0;
function show()
{
counter += 1;
alert(counter);
document.getElementById('disp').innerHTML = counter+"<br>";
if (counter < 5 )
// setTimeout(function(){show()},2000);
setTimeout(show,2000);
}
</script>
<button onclick = "setTimeout(show,2000)">Try it</button>
<div id="disp">Start:</div>
<script>
show();
</script>
</body>
</html>