Skip to content

Instantly share code, notes, and snippets.

@Kielx
Last active June 6, 2020 18:20
Show Gist options
  • Save Kielx/b9d7f053b7b0873068c8cc93d3e8df87 to your computer and use it in GitHub Desktop.
Save Kielx/b9d7f053b7b0873068c8cc93d3e8df87 to your computer and use it in GitHub Desktop.
sumPrimes scrimba coding challange
//function sumPrimes sums all prime numbers up to the provided number
const isPrime = function (number) {
if (number <= 2) {
return 1;
}
for (let i = 2; i < number; i++) {
if (number % i === 0) {
return 0;
}
}
return 1;
};
const sumPrimes = function (num) {
sum = 0;
for (i = 2; i <= num; i++) {
if (isPrime(i)) {
sum += i;
}
}
return sum;
};
console.log(sumPrimes(977));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment