May 20, 2013
what is wrong with my code? it should output 0-9 but it failed to do so. I think the error is in go()
User2384484’s Question:
Can you help me debug this code? I can’t see the errors in it. There is also no ouput to determine the error.
function go() { var procedures = []; for (var i = 0; i < 10; i++) { procedures[procedures.length] = function () { alert("You are now " + i + " years old"); } run_procs(procedures); } function run_procs(procs) { for (var i = 0; i < procs.length; i++) { procs[i](); } } go(); }
You have executed the function inside the function. Put go();
outside.