Summing Prime numbers

Tell us what’s happening:
Here is my code for summing prime numbers up to a given number but its not passing the tests and I don’t understand why. Please help

Your code so far


function sumPrimes(num) {
var sums = 0;
for(var i = 2; i <= num; i++);
if(isPrime(i)){
  return sums += i;

}
return sums;
}

sumPrimes(10);

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 8.1.0; CPH1909 Build/O11019) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36.

Challenge: Sum All Primes

Link to the challenge:

What is isPrime? Without knowing how you’ve defined that function, we can’t see what the issue is

2 Likes

You need a method of determining if a number is prime or not.

Ok i have done this: @cherylm @DanCouper

function sumPrimes(num) {
 var sums = 0;
function isPrime(num) {
  for(var i = 2; i < num; i++)
    if(num % i === 0) return false;
  return num > 1;
}

for(var i = 2; i <= num; i++);
if(isPrime(i)){
  return sums += i;

}
return sums;
}

sumPrimes(10);

I didn’t analyze your logic or run the code, but the first thing I noticed is you seem to have syntax errors with your for loops.

what is this return statement doing?