Sum All Primes - I solved it but it's not working in FCC. It works in JSbin and


I was trying to solve the Intermediate Algorithm Scripting: Sum All Primes problem. I came up with the code below and it worked in jsbin and but it’s not being accepted in freecodecamp.

I know it’s not that good. It seems quite a brute way of solving the problem. But this is what I could come up with at my current state.

Please let me know if there is any problem with this.

sumPrimes(977)` should return 73156 part is not working on FCC but it gives correct answer on jsbin or


Mycode so far

function sumPrimes(num) {
  let prime = [];
  let factors = [];
  for (let i=1; i<=num; i++){
    factors = [];
    for (let j=1; j<=i; j++){
      if (i%j==0){
     if (factors.length<=2){
  prime = prime.reduce((a, b) => a+b);  
  return prime ;


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:

So, inefficiency is the reason.I guess I have to find another way then.