Ritesh Kumar Ritesh Kumar - 4 months ago 8
jQuery Question

How to execute a JS statement multiple time in browser console

When I write this in JavaScript statement in browser console

inbreedingInvite('74011','107433','');


and hit enter it sends an invite to user number 107433 to join group id 74011. If i want to invite another user I have to do it manually by changing user number.

Can anyone help me by telling how this can be automated, till now I have got this:

(function myLoop (i) {
setTimeout(function () {
console.log("inbreedingInvite('74011','" + i + "','');"); // your code here
if (--i) myLoop(i); // decrement i and call myLoop again if i > 0
}, 1000)
})(10);


but with this code it only output the statement in the console, doesn't actually executes it on the webpage

Answer

Everyone is correct up top (comments). Perhaps it will help to see it as a full code block:

(function myLoop (i) {          
   setTimeout(function () {   
      inbreedingInvite('74011',i,'');
      if (--i) myLoop(i);      //  decrement i and call myLoop again if i > 0
   }, 1000)
})(10);