# Sum All Primes, possible error in fcc console?

Tell us what’s happening:
I get error with this task when inputs above certain number, returns incorrect result:

1. I’ve tested in chrome console and result from 977 correctly results with 73156, meaning my code should be fine.
2. The result in FCC console each time returns different result: 8275, 7141, 5117 etc.
From what I understand, for some unknown reason, the loop breaks before reaching 977 and returns whatever is there. I would guess it would be to limit harmful while loops or smth…

``````
function sumPrimes(num) {
let i = 0;
let primesArr = []

while(i<=num){
let divides = []
for( let j=0; j<num; j++){
if(i%j===0){
divides.push(true)
}
}
// console.log(i, divides)
if(divides.length<=2){
primesArr.push(i)
}
i++
}
// console.log(primesArr)
let sumArr = primesArr.reduce((a,b) => a + b, 0)
console.log(sumArr-1)
return num;
}

sumPrimes(977);
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36`.
a hint if you wish to optimize your code: you’re checking to see if a number has less than or equal to two divisors (shown in the lines `divides.push(true)` and `divides.length<=2`. But these two divisors are 1 and itself. So you can reformat the loop to assume that the divisors 1 and itself will always be there, and exit the loop if `i % j === 0`