0
I’m starting in the world of javascript and I have a question that kills my logic. I want a method to repeat a number of times every certain time, but not working when using the repetition structure For, can you help me understand please?
var repetirFunc = function(){
for (var i = 1; i <= 11; i++){
setTimeout(function(){
console.log('Texto');
}, 2000);
}
}
repetirFunc();
In the example above I would like the "text" to repeat 11 times every 2 seconds, but it takes 2 seconds only the first loop, after that it launches you on the screen all repetitions.
Image 1: The first 2 seconds is like this
Image 2: After the first 2 seconds, he throws you the 11 repetitions at once
thank you
It worked Gabriel, thank you very much.
– Moisesmagno
If you solved the problem (and you don’t need anything else), you can mark it as the correct answer... and nothing. ;)
– Gabriel Katakura