I have an example on this code:
<script>
for(var i=1; i<3; i++){
setTimeout(function(){
say("HELLO NUMBER " + i);
}, i * 2000);
}
function say(text){
alert(text);
}
</script>
And output I need is :
alert("HELLO NUMBER 1");
alert("HELLO NUMBER 2");
But in this case, I still get output :
alert("HELLO NUMBER 3");
Anyone can help for this? thanks :)