Tell us what’s happening:
My code returns 73156 on the function call with 977 but does not pass the test. Can somebody tell me what is the problem?
function sumPrimes(num) {
let primeNos = [];
for (let i = 2; i <= num; i++) {
let counter = 0;
for (let j = 0; j < i; j++) {
if (i % j === 0) {
counter += 1;
}
}
if (counter === 1) {
primeNos.push(i);
}
}
return primeNos.reduce((a, b) => a + b);
}
sumPrimes(977);
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-primes/