Javascript stuck

didn’t work

   **Your code so far**

function sumPrimes(num) {
function isPrime(num) {
   for (let i = 2; i <= 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)) 
     sum += 1;
 }
  return sum;
}
console.log(sumPrimes(10));
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36.

Challenge: Sum All Primes

Link to the challenge:

Two questions for you to think about. First, you have this isPrime function, which makes sense, but what is that checking? It is written to expect its own parameter, num which is not the same as num in the outer function, but when you call it…what value of being passed in?

Second, if you do find a prime…what should be added to sum?

sir,
i take this anwer from get hint option now i have done the test. but kindly let me know if in 1st loop instead of “i<= Math.sqrt(num)” can we only put “i<num” ??

Can you come up with an argument why you want to do this and the pros and cons of it?

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