Sum All Primes in Intermediate Algorithm Scripting

Hello, I think my code is correct and the result expected is wrong
because the sum of prime numbers under 10 is 18 not 17

  **My code so far**

function sumPrimes(num) {
let primeArr = [];
let isPrime = function(x) {
  let inc = 0;
  for (let i=0; i <= x; i++) {
    if (x % i ==0) {
      if(inc > 2) {return false}
  return true;
for (let y= 1; y<=num; y++) {
  if(isPrime(y)) {
console.log(primeArr.reduce((a,b) => a+b));
return num;

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0

Challenge: Sum All Primes

Link to the challenge:

1 is not a prime number.

You may need to improve upon your code a bit.

1 always divides into x, so why not start at 2?

Also, you don’t need to go all the way up to x.

Why build a prime array here

just to sum it up here? Just sum from the start!

1 Like

Thank you i feel dumb

We’ve all been there.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.