Tell us what’s happening:
Describe your issue in detail here.
my code returns 18 when it is supposed to return 17. I want to know where is the error in my code.
Your code so far
function sumPrimes(num) {
function checkPrimes(number){
for(let i = 2; i< number; i++){
if(number % i === 0) return false;
}return true;
}
let answer=0;
for(let j=0; j<= num; j++){
if(checkPrimes(j)){
answer += j;
}
}
return answer;
}
console.log(sumPrimes(10));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Sum All Primes
Link to the challenge: