msimic
January 18, 2018, 12:35pm
1
Tell us what’s happening:
Can anyone tell me why this code fails when number 977 is tried? It works with 10 and 17.
Thanks in advance!
Your code so far
function isPrime(num) {
var count = 0;
for(var i = 1; i <= num; i++)
if(num % i === 0) count++;
if(count === 2) return true;
return false;
}
function sumPrimes(num) {
if(num <= 1) return 0;
var sum = 0;
for(var curr = 2; curr <= num; curr++)
if(isPrime(curr)) sum += curr;
return sum;
}
sumPrimes(10);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
.
Link to the challenge:
https://www.freecodecamp.org/challenges/sum-all-primes
There doesn’t seem to be a problem. Your code passes when I tried it.
msimic
January 18, 2018, 12:43pm
3
lol
Glad it passes somewhere. I guess it might be the memory problem? Read some comment about that on Youtube video about this challenge.
Do you get any sort of error in the browser console?
msimic
January 18, 2018, 12:46pm
5
You mean error in console related to the whole website or?
I do get 2 dead object errors from freecodecamp website.
EDIT: Interesting thing. I tried the same code on my sisters 2015 MacBook Pro on Chrome browser and it works.
I was going to ask you to try on another browser on your computer
Or try hitting the reset button first.
msimic
January 18, 2018, 12:56pm
7
Tried it on MY laptop on Google Chrome. Works again.
So, it’s the problem with Firefox. I’ll try restarting it.
I thought my code doesn’t work for some reason (I didn’t know the reason) and i said some really bad words while trying to solve this.
Thank you again for help!