Sum all primes algorithm error on test

Sum all primes algorithm error on test
0

#1

I don’t understand why the test of this exercise return an error:
sumPrimes(977) should return 73156.

If I run this code on my browser, with the console, I correctly receive 73156 as the return value:

function sumPrimes(num) {
  let sum = 0;

  while(num > 1) {
    sum = sum + isPrime(num);
    num--;
  }

  return sum;
}

function isPrime(n) {
  let divisor = n - 1;
  let found = false;

  while(divisor > 1) {
    if(n % divisor == 0) {
      found = true;
      break;
    }

    divisor--;
  }

  if(!found) {
    return n;
  }
  
  return 0;
}

So, why the test doesn’t pass?


#2

If you search the forum you will find this question has been discussed before…


#3

Thanks, I found this post helpful.