Tell us what’s happening:
where is the mistake in my code?
what i found so far is number 9 is showing as prime number in my code (why?)
Your code so far
function sumPrimes(num) {
var b=2;
var re=0;
var c=[];
function isPrime(n)
{
if(n<2)
return false;
while(b<=parseInt(n/2))
{
if(n%b==0)
{return false;}
b++;
}
return true;
}
for(let i=0;i<=num;i++)
{
if(isPrime(i)==true)
{
re+=i;;
}
}
return re;
}
console.log(sumPrimes(977));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
.
Challenge: Sum All Primes
Link to the challenge: