Not passing second test case - Sum All Primes

Tell us what’s happening:
So I tried to follow the pseudocode on the sieve wiki page and this is what I have, and this passes when the test num is 10. The issue is 977, it says the sum is 72,179. I don’t really know whats going on. I also tried letting the last for loop be i <A.length instead of num and there was no difference. Advice is always appreciated.

Your code so far

function sumPrimes(num) {
    let currentNumber = 0;
    let sum = 0;
    let A = [];
  //An array of booleans from [2-num] set to true
  for (let bool = 2; bool <= num; bool++){
    if (bool <= num){
    //supposed to set prime vals true and non primes false
  for (let i = 2; i <= Math.sqrt(num); i++){
      if(A[i] === true){
        for(let j = Math.pow(i,2); j <= num; j+=i){
          A[j] = false;
  //goes through and adds the primes
  for(let i = 2; i <= num; i++){
    if(A[i] === true){
      currentNumber = i;
      sum += currentNumber;
  return sum;


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0

Challenge: Intermediate Algorithm Scripting - Sum All Primes

Link to the challenge:

I think you have an off by two error here. Your array only has num-2 elements.

Yes, that’s a good spot. The logic doesn’t quite work after that, as everything’s shifted by two. You can change a single value in your function and it works perfectly.