# Sum All Primes Stuck!

Sum All Primes Stuck!
0

#1

Hi Guys, I am stuck at this challenge for about 2 days and I need help, please. Here is my best code I think

``````
function sumPrimes(num) {
var prime = [2,3,5,7];
for (var j = num ; j > 1 ; j-- ){
var devide2 = j/2;
var devide3 = j/3 ;
var devide5 = j/5;
var devide7 = j/7;
if (Math.floor(devide7) !== devide7 ){
if (Math.floor(devide2) !== devide2 ){
if (Math.floor(devide3) !== devide3){
if (Math.floor(devide5) !== devide5){
prime.push(j);
}
}
}
}
}
var square = [];
for ( var i = 0 ; i < prime.length ; i++){
square.push(prime[i]*prime[i]);
}
var resultArr = [];
for ( var k = 0 ; k < prime.length ; k++){
if (square.indexOf(prime[k]) === -1){
resultArr.push(prime[k]);
}
}

var res = resultArr.reduce(function (a,b){return a+b;},0);
return resultArr;
}

sumPrimes(977);

``````

I know it won’t work for larger nums so I tried a General Solution but Nothing new! here is the new trail!

``````
function sumPrimes(num) {
var nums = [];
var test = '' ;
for (var i = 2 ; i <= num ;i++ ){
nums.push(i);
}
var rrr = 'a';
function fil (a){
return a % 2 == 0;
}
rrr = nums.filter(fil);
return rrr ;
}

sumPrimes(10);

``````

#2

Hi Ahmed,

Here is a suggested algorithm I’d study a bit before implementing. It’s rather effective.

#3

Mate, U don’t know how much U helped me. <3 <3 <3 I owe U my Friend