Created
October 2, 2018 05:39
-
-
Save jepras/81c2fb1d36ec57c54537a99badd4d685 to your computer and use it in GitHub Desktop.
Use a isPrime method to return true on primes. Then loop through and add result to output if isPrime.
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(num) { | |
function isPrime(num) { | |
if(num < 2) return false; | |
for (var i = 2; i < num; i++) { | |
if(num%i==0) | |
return false; | |
} | |
return true; | |
} | |
var output = 0; | |
for(var i = 0; i <= num; i++){ | |
if(isPrime(i)) { | |
output =+ output + i; | |
} | |
} | |
return output; | |
} | |
sumPrimes(10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment