Tell us what’s happening:
So, my second while loop is doing it’s job of removing all composite numbers, but I just don’t know how to make it stop. Any help would be appreciated!
Your code so far
function sumPrimes(num) {
var arr = [];
var digit1 = 1;
while (digit1 < num){
digit1++;
arr.push(digit1);
}
var index = 0;
var digit2= arr[index];
var digit3= arr[index];
var del;
while(Math.pow(digit2, digit2)<num){
while (digit3 <= num){
digit3 += digit2;
del = arr.indexOf(digit3);
arr.splice(del,1);
console.log(arr);
}
index++;
}
return ;
}
sumPrimes(10);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/sum-all-primes