I'm starting in the javascript world and I'm having a question that kills my logic. I want a method to repeat a number of times every time, but not working when using the For loop, can you help me understand it please?
var repetirFunc = function(){
for (var i = 1; i <= 11; i++){
setTimeout(function(){
console.log('Texto');
}, 2000);
}
}
repetirFunc();
In the above example I would like the "text" to repeat 11 times every 2 seconds, but it takes only 2 seconds for the first loop, after which it launches all the repetitions on the screen.
Image 1: The first 2 seconds stays like this
Image2:Afterthefirst2seconds,itlaunchesthe11repetitionsatonce
Thank you