Sum All Primes: Code Fails 1/3 tests in Firefox, but Passes in Chrome

Hey friends! I’m making great progress thanks to the wonderful people on gitter and elsewhere. I’m learning a LOT!

I recently worked on the “Sum All Primes” challenge in the intermediate algorithms and ran across something interesting:

The following code fails 1/3 of the tests on Firefox, but passes them all in Chrome. I put in some useful console.logs to figure out what’s happening, and it seems the first for loop, the one that uses i as its iterator is stopping before it should. Take a look at the console log and you’ll see execution stops well before i<num is satisfied when num = 977.

Now I passed just fine on Chrome, so I’m not really asking for a way to pass the challenge. I’m mostly interested if anyone can explain to me what Firefox is doing here that’s causing it to stop short.

Code

function sumPrimes(num) {
  console.log("NewRun$$$$$$$$$$$$$$$$$$$ " + num);
  var isPrimeBool = true;
  var output = [];
  for (i=2;i<=num;i++) {
    isPrimeBool = true;
    for (j=2;j<i;j++) {
      if (i%j === 0) {
        isPrimeBool = false;
      }
    }
    if (isPrimeBool === true) {
      output.push(i);
    }
  }
  console.log(output);
  output = output.reduce(function(acc,val) {
    return acc + val;
  });
  console.log("Output: " + output);
  return output;
}

sumPrimes(10);

It’s timing out on the third test. It looks like this runs just a little bit slower in Firefox than in Chrome, and is hitting our infinite loop protection. When I run your code in Firefox with //noprotect, it passes.