# How exactly does this code run?

Hello guys~
I was doing the sum up the prime task and saw a code that is easy to read and to understand.
However, I have a question regarding the for loop part.

Below is the correct one
`function isPrimes(num)
{
for (var i=2; i < num; i++)
{
if (num % i=== 0) {
return false;
} // if
}//forloop

return true ;

}//isPrimes

function sumPrimes(num){
var sum = 0;
for (var i=2 ; i <=num ; i++){
if(isPrimes(i)){
sum += i;
}
}
return sum;
}
sumPrimes(10);
`

When I tried to do write it myself, I put `return true`inside the for loop, like this
`function isPrimes(num)
{
for (var i=2; i < num; i++)
{
if (num % i === 0)
{return false;
} // if
else{
return true ;
}
}//forloop

}//isPrimes
`

The second function remains the same but the result of`sumPrimes(10)` became 24 instead of 17.
Can anyone explain the logic for me?? Will be very appreciated. Thanks in advance!

what is this `is_number` ? i dont see any variable `is_number` and can you please share the challenge link so that we can test and see what going on

Sorry it’s a mistake.
should be
`if (num % i === 0) { return false;}`

`https://www.freecodecamp.org/challenges/sum-all-primes`

Thank you

i just checked it working fine.

``````    if (num % is_number === 0) {

return false;
``````

It was the mistake. now its working fine.
17

My result is 24

eliminate the `else section.`. and place `return true` in the `isPrimes` function scope .
Cause right now its not returning properly from the function.its stuck in `if` statement.
so just `return true` in function scope. like this :

``````function isPrimes(num){
for (var i=2; i < num; i++){
if (num % i=== 0) {
return false;
} // if
}//forloop
return true ;
}
``````