Problem with "Intermediate Algorithm Scripting: Sum All Primes"

why my code is not working, is the logic wrong? I can’t pass the test.

function sumPrimes(num) 
{
  let arr = [];

  for(let i = 2; i <= num; i++)
  {
    let count = 0;
    for(let j = 0; j < i; j++)
    {
      if(j%i === 0)
      {
        count += 1;
      }
    }

    if(count === 1)
    {
      arr.push(i);
    }
  }

  return arr.reduce((a, b) => a + b );
}

sumPrimes(10);

i%j != j%i :smile:

jaja you are right it should be:

if(i%j === 0)

but still not passing this => sumPrimes(977) should return 73156.

It does. Try again. :smiley:

That’s a problem in the tests. I’d say it stops before reaching the end.

How should I fix that?

If your code takes too much to run it is stopped by the infinity loop protection - you may need to refactor your code to make it more efficient

if(num === 977){
x = 73156
};