# Sum of the primes

**URL:** <https://forum.freecodecamp.org/t/sum-of-the-primes/30087>\
**Category:** General\
**Created:** [August 21, 2016, 11:40pm UTC](https://forum.freecodecamp.org/t/sum-of-the-primes/30087 "2016-08-21T23:40:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebtn](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@sebtn](https://forum.freecodecamp.org/u/sebtn)\
**Post date:** [August 21, 2016, 11:40pm UTC](https://forum.freecodecamp.org/t/sum-of-the-primes/30087/1 "2016-08-21T23:40:24Z")

</div>

I’m not sure why the sum of all primes is different fro the test…  
sumPrimes(10) should return a number. checks  
sumPrimes(10) should return 17. checks  
sumPrimes(977) should return 73156, but mines returns 72179

Any help is much appreciated

`function sumPrimes(num) {`

```
var primes = [];

 function isPrime (number) {
   for (var i = 2; i<number; i++) {
     if(number%i === 0) 
     {return false;}     
   }
   return true;
 }
  for(var j=2; j<num; j++) {
    if(isPrime(j)) {
      primes.push(j);
    }
  }

  
function add (a , b) {
    return a + b;
  }
  
  var result = primes.reduce(add)
  
 return result;
}

```

Why put all the values in an array and then sum them does not add correctly? this is wierd,.

What am I missing?

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 16, 2021, 5:28am UTC](https://forum.freecodecamp.org/t/sum-of-the-primes/30087/3 "2021-01-16T05:28:58Z")

</div>

Closed on January 16, 2021, 5:28am UTC


