We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 700a8af commit 7a1b86aCopy full SHA for 7a1b86a
09-intermediate-algorithm-scripting/13-sum-all-primes.js
@@ -10,3 +10,24 @@ Rewrite sumPrimes so it returns the sum of all prime numbers that are less than
10
- sumPrimes(10) should return 17.
11
- sumPrimes(977) should return 73156.
12
*/
13
+function sumPrimes(num) {
14
+ let sum = 0;
15
+ for (let i = 2; i <= num; i++) {
16
+ if (isPrime(i)) {
17
+ sum += i;
18
+ }
19
20
+ return sum;
21
+}
22
+
23
+function isPrime(num) {
24
+ for (let i = 2; i < num; i++) {
25
+ if (num % i === 0) {
26
+ return false;
27
28
29
+ return num > 1;
30
31
32
+console.log(sumPrimes(10));
33
+console.log(sumPrimes(977));
0 commit comments