Potential Infinite Loop error for large n values

Tell us what’s happening:
Somehow, “potental infinite loop” flags me down for the biggest number. In browser i’m getting really good speeds, but the code-editor flags me down.

i don’t think there’s math formulas for this, I’ve looked.

Your code so far


function primeSummation(n) {

let arr = 0;
    let temp = n;

    for (let x = temp; x >= 2; x--)
    {  
      (function() 
      {
        // debugger;
        const isEven = x % 2 === 0;
        let inc = isEven ? 1 : 2;
        let factors = [1, x];
        temp = factors[1]

        for (var check = isEven ? 2 : 3; check <= Math.sqrt(x); check += inc)
        {
          if (x % check !== 0) 
          {
            continue;
          }
          return;         
        }
        if (x === 1 || x === n) return;

        arr+=x
      })()
    }

    console.log(arr)
    return arr;
}
primeSummation(2000000);

Your browser information:

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

Challenge: Problem 10: Summation of primes

Link to the challenge:
https://www.freecodecamp.org/learn/coding-interview-prep/project-euler/problem-10-summation-of-primes