1// prime numbers from zero up till a certain number
2const sumPrimes = (num) => {
3 let primes=[];
4 // computing prime numbers from 0 uptill a number num
5 for (let i = 0; i <= num; i++) {
6 let flag = 0;
7 // looping through 2 to user input number
8 for (let j = 2; j < i; j++) {
9 if (i % j == 0) {
10 flag = 1;
11 break;
12 }
13 }
14 // if number greater than 1 and not divisible by other numbers
15 if (i > 1 && flag == 0) {
16 primes.push(i); // pushing all prime numbers in this array
17 }
18 }
19 return primes;
20}
21console.log(sumPrimes(10)) // Expected output: 17