Tell us what’s happening:
1+2+3+5+7 = 18
The test says its sum should be 17 with an input of 10 but that is mathematically impossible.
Your code so far
function sumPrimes(num) {
let pSum = 0;
function pTest(test){
let p = true;
for(let i = 2; i < test; i++){
if((test%i) === 0){
return false;
}
//console.log(`test%i:${test%i}, p: ${p}, test:${test}`);
}
return p;
}
console.log(pTest(11))
for(let j = 0; j <= num; j++){
if(pTest(j)){
pSum += j;
}
//console.log(`pSum: ${pSum}, j: ${j}`);
}
return pSum;
}
console.log(sumPrimes(977));
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0
.
Challenge: Sum All Primes
Link to the challenge: