Unexpected results? Intermediate Algorithm Scripting: Sum All Primes

I’m currently working on the Intermediate Algorithm Scripting: Sum All Primes problem, and I’m experiencing some unexpected results. The objective is to write code that will sum all of the prime numbers, up to and including the provided number. The code I wrote does just that–in Visual Studio Code. It doesn’t seem to work consistently in the freeCodeCamp environment though, and any numbers passed into the function that are higher than 661 return an unexpected value.

Would someone might taking a look at my code and helping me figure out what’s going on?

function sumPrimes(num) {

let primeNumbers =[2];
let prime = 0;

//iterate down through every number from num to 2
for (let testNumber = num; testNumber > 2; testNumber--) {
    //determine if testNumber can be divided by any number less than itself
    for(let j = 2; j < testNumber; j++) {
        let mod = testNumber % j;
        //if testNumber is divisible by a number less than itself, increase prime
        if (mod == 0) {
    //if prime hasn't been increased, then add testNumber to the array of prime numbers
    if (prime == 0) {
    //reset prime to 0
    prime = 0;
//return the sum of all of the prime numbers
return primeNumbers.reduce((total, number) => total + number, 0);


it means that above 661 your code takes too much time to execute and it is prematurely stopped by the infinite loop protection which is in place to avoid your browser freezing if an infinite loop is accidentally created

Interesting. So, to pass the challenge I’ll need to start over with a different solution that’s more efficient. Thanks