Hello everyone,
I am having a tough time with the sum All primes algorithm. The code I have returns the correct values on JS bin without any console errors:
js bin - sum all primes
When I run the code on code camp, it throws this error: "potential infinite loop at line 8… " which is where I set “notPrime = false” below. I have tried adding //noprotect as line 1 of code. The code runs and returns the sum, but the test do not pass.
var arr = []; //store prime numbers here
//primeBelow pushes prime numbers <= val into arr array
function primeBelow(val){
//test all numbers between 2 and val for prime
var notPrime;
for (var numTest = 2; numTest <= val; numTest++){
notPrime = false;
//divide i by all numbers below i.
//If any division has zero remainder, its not prime.
for (var i = 2; i<=numTest; i++){
if (numTest%i === 0 && numTest != i){
notPrime = true;
}
}
//if the prime test is passed, push the value to arr
if (notPrime === false) {
arr.push(numTest);
}
}
return arr;
}
//sumPrimes call the primeBelow function and sums all prime values below num
function sumPrimes(num){
var sum = 0;
primeBelow(num);
arr.map(function(val){
sum += val;
});
console.log(arr, sum);
return sum;
}
sumPrimes(977);
I don’t see where the infinite loop warning is coming from, or what I am missing. 
Browsers tried: Chromium and Firefox
Any insights would be greatly appreciated. Thanks for reading!