After pulling my hair out trying to figure out why my code wasn’t passing (although it did on repl.it), I found some posts saying that FCC’s tests include a timer and my code apparently fails it. First, and I’m not complaining about a free service, but it’d sure be nice if the results pane said so, rather than just saying “sumPrimes(977) should return 73156” (which my code actually does). But more to the point, could someone please tell me what is timing out here? My code checks for the easy ones (2,3,5) early in the process, so I’m hoping that would be efficient enough:
function sumPrimes(num) {
var sum = 0;
for (let current = 2; current <= num; current ++) {
var isprime = true;
for (let i = 2; i< current; i++) {
if (current % i == 0) {
isprime = false;
break;
}
}
if (isprime) {
sum = sum + current;
}
}
return(sum);
}
Thanks again to all.