Sum All Primes - function isPrime()

function isPrime(x) {
  for (let i = 2; i < x; i++) {
    if (x % i === 0) return false;
  }
  return x !== 1 && x !== 0;
}

Hi everyone,

I am wondering for x = 2, does it get passed into this function? Or, does it not get passed because the for loop specifies that i < x?

If x = 2 does get passed, I don’t see how it returns true as 2 % 2 === 0, so return false.

This is from the Sum All Primes challenge.

Thanks

as the loop doesn’t execute because i < x is false, it is this part after the loop that is executed:

1 Like

Wow thank you so much for the quick reply!