# Sum All Primes, output too high

Tell us what’s happening:
with higher numbers (977) i keep getting too high a number as output. i have no idea what i’m doing wrong

``````function sumPrimes(num) {
var a = [2,3,5,7];
for (var i = 2; i < num;i++){
if (i % 2 !== 0){
if( i % 3 !== 0){
if(i % 5 !== 0){
if(i % 7 !== 0){ a.push(i);}}}}
}
var total = a.reduce(function(sum, value) {
return sum + value;
}, 0);
console.log(a);

}

sumPrimes(977);
``````

Your Browser User Agent is: `Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36`.

You’re generating numbers that aren’t prime. 121 jumps out because it’s the square of 11.

1 Like

thank you!

now i truly have no idea what i’m doing.

yeah, i saw something like that in the wikipedia article on the Sieve of Eratosthenes.
still don’t get it yet.
what is the absolute mathematical proof that a number is prime or not, using variables?
i thought eliminating all the smallest possible primes was enough, but it appears i’m wrong.

you helped me a lot, thank you.
but i guess i have to take a week and figure this out like i did with all the other problems

i think i understand what it is doing
its 1) making an array of numbers 2) sorting them into piles of prime, or multiples of prime 3) then spits out only primes.

wouldn’t that slow the process down a ton if i make a whole array of numbers, sort through those numbers and put them into two new arrays, then take the one array i need and multiply it?