0

So my problem is that i delcared 2 variabled outside a loop and i got inside the loop a callback function what should return with an increase statement based if its errored or worked but like in this example if i return with that statement it only go through to the loop but dont change the variables outside how would i get this work?

code Example here:

    let Correct = 0;
    let Errors = 0;
    let someArray;
    for(let index = 0; index < someArray.length; index++) {
        const Input = someArray[index]
        functionWithAnCallback(Input, (err, output) => {
            if(err) return Errors++;
            //do stuff here that is not important
            return Correct++;
        })
    }
DevYukine
  • 51
  • 4
  • Why are you returning `Error` and `Correct`? It could be that is making the problem. – MotKohn Jul 11 '17 at 03:12
  • `return`ing from asynchronous callbacks is pointless. And the variables *do* get changed by the callback, they just won't have been changed by the end of the loop. – Bergi Jul 11 '17 at 03:12
  • My answer before this was closed: https://pastebin.com/uPw3Vm8F – Jack Guy Jul 11 '17 at 03:13

0 Answers0