Sum All Primes - does not pass for 977

Sum All Primes - does not pass for 977
0

Tell us what’s happening:

The answer required is: sumPrimes(977) should return 73156.

The below code does not pass for the number 977. However I have used other sites to check my answer and it comes out to be 73156. Have I done something wrong in my code?

Your code so far


function sumPrimes(num) {

var x = 0;
var y = 0;
console.log(num)

for (var i= 2; i<=num; i++){
  for (var j= 1; j<=i; j++){
    if (Number.isInteger(i/j) === true) {
        x = x + 1;
        }

} 

 //console.log(i)
 //console.log(x)
 if (x < 3) {
   y = y + i;
 }
console.log(y)
  var x = 0;
      
}

  return y;
}

sumPrimes(977);

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-primes/

You are probably running into the infinite loop protection. FCC uses a timeout in its challenges to protect campers from accidentally crashing their browsers with infinite loops or infinite recursion. If you re-evaluate your solution to make it more efficient, you will not hit the timeout.

@haskumar, I tested your code and just removed the console.logs, it was successful. Here’s the code I used:


function sumPrimes(num) {
  var x = 0;
  var y = 0;

  //console.log(num)

  for (var i= 2; i<=num; i++){
    for (var j= 1; j<=i; j++){
      if (Number.isInteger(i/j) === true) {
        x = x + 1;
      }

    }

    //console.log(i)
    //console.log(x)
    if (x < 3) {
      y = y + i;
    }
    var x = 0;

  }

  return y;
}

console.log(sumPrimes(977));

Still not working for me.

What error does it show to you?