Solution part that does not make sense to me

Tell us what’s happening:
Describe your issue in detail here.
sp in the solution the loop is initiated at (i) and then stopping conditions is when (i <= Math.sqrt(num)), so it stops at i less than or EQUAL TO sqrt of 9 => 3
so if we provided num at 9, sqrt is 3, so (i) inside the loop will reach the value 3,(9%3=0)
but 9 is not a prime number !!
when I console.log the num for some reason it never reaches 3, it goes 2.3, 2.4, 2.6,…2.8
not sure how is this possible!

  **Your code so far**

function sumPrimes(num) {
let arr=[];
// for (let i=num; i >= 0; i--){
//   arr.push(i)
      

// }
// let primeNums = arr.filter(number => number%number)

function isPrime(num){
  if (num < 2) return false;
  for(let i=2; i <= Math.sqrt(num); i++){
    console.log(Math.sqrt(num), i)
    if(num%i == 0) return false
      
  } return true
}

let sum =0;
for (let i=2; i < num ; i++){
  if (isPrime(i) === true) {
    sum += i
    
  }
}
// console.log(sum)
//  console.log(isPrime(3)) 

return sum;

}
sumPrimes(10);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36

Challenge: Sum All Primes

Link to the challenge:

I’m a bit confused about what you are asking.

isPrime(9) will return false as you’ve written it above because 9%3===0.

nvm, I was confused after a long session in that section. I see how confusing this is. I get it now.
thanks for the response

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.