Tell us what’s happening:
Hey all! I’m running this exact same code on my laptop, locally, and when I give it 977 I’m getting the correct output (73156), is this a memory issue? Hope there’s a fix! Thanks everyone!
Your code so far
function isPrime(num) {
let count = 0;
for (let i = 1; i < num+1; i++) {
if (num % i === 0) {
count++;
}
if (count > 2) {
return false;
}
}
return true;
}
function sumPrimes(num) {
let sum = 0;
for (let i = 2; i <= num; i++) {
if (isPrime(i)) {
sum += i;
console.log(i);
}
}
return sum;
}
console.log(sumPrimes(977));
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/75.0.3770.90 Chrome/75.0.3770.90 Safari/537.36
.
Link to the challenge: