Tell us what’s happening:
Why is the ‘2’ being spliced when it doesn’t satisfy the condition in the if statement in the second ‘for’ loop?
**Your code so far**
function sumPrimes(num) {
let total = [];
for (let i = 2; i <= num; i++) {
let qqq = total.push(i);
};
let newAnswer = total.slice();
for (let p = 0; p < total.length; p++) {
if (num % total[p] !== 0) {
newAnswer.splice(p, 1);
};
};
console.log(newAnswer);
};
sumPrimes(10);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36
Challenge: Sum All Primes
Link to the challenge: