Tell us what’s happening:
Help why is my code failing for test sum Primes(977) should return 73156.
yet that’s the right answer i get on my console when testing the code
Help
Your code so far
function isPrime(num) {
if(num<2) {
return false;
}
for(let i=num-1;i>1;i--) {
if(num%i===0) {
return false;
}
}
return true;
}
function sumPrimes(num) {
let i = 1;
let sum = 0;
while(i<=num) {
if(isPrime(i)) {
sum+=i;
}
i++;
}
return sum;
}
sumPrimes(10);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.
Could you do one little favor for the forum though? Wrapping those completed solutions in spoiler tags will hide them from those still working on that challenge. Anyone can still see your work by clicking on it though. [spoiler]This text will be blurred[/spoiler]
Thank you
PS @MatricksDeCoder: Your code ran fine for me too. Not at all slow so probably not timing out.