So the code return the correct values but the test doesn’t pass.
I can’t seem to grasp why tho…
I summon your help.
please
Your code so far
let sum = 0;
let check;
function sumPrimes(num) {
for (let i = num; i > 1; i--) {
for (let j = i-1; j > 1; j--) {
if (Number.isInteger(i/j) == false){
check = false;
} else {
check = true;
break;
}
}
if (check === false) {
sum += i
}
}
return sum
}
console.log(sumPrimes(977));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36.
When you declare sum and check outside of the function body they basically become global variables and thus sum does not start over at 0 for each function call.