Help with Sum All Primes challenge

I wrote this code for “Sum All Primes” challenge:

function sumPrimes(num) {
var primes = [], sum = 0, i;

for (i = num; i > 1; i–) {
if (num % i === 0) primes.push(i);
}

for (i = 0; i < primes.length; i++) sum += primes[i];

console.log(sum);

return sum;
}

Passes the first two tests, but in the last one, passing 977, it returns the same number.

Couple things. Your code is only checking to see if one number is prime. You need another loop to check every number less than num

The alg for prime is not quite right. You don’t want to push to prime unless the only factors are 1 and itself. So any mod result of zero for 2 to num-1 means not prime.

Your code pushes 2 5 and 10 but should push 2 3 5 7. In the other test pushes 977 which is prime but you have to check every number 2 to 977. There are a bunch.

You have made a really good start on the challenge. Hope this helps.