Last active
June 6, 2020 18:20
-
-
Save Kielx/b9d7f053b7b0873068c8cc93d3e8df87 to your computer and use it in GitHub Desktop.
sumPrimes scrimba coding challange
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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