Sum All Primes

function sumPrimes(num) {
  //素数:大于1,只能被1和本身整除的数
  let sum = 0
  for(let i=2; i<=num; i++) {
    let isPrime= true
    for(let j=1; j<=i; j++) {
      if(j==1 || i==j){
        continue
      }
      if(i%j==0){//被1和本身以外的数整除了,非质数
        isPrime= false
        break
      }
    }
    if(isPrime){
      sum+=i
    }
  }
  return sum;
}

sumPrimes(10);

测试数据:

sumPrimes(10) should return 17. sumPrimes(977) should return 73156.

别人家的孩子,心情也很重要,也不看了,要沉浸在完成的喜悦中,有些激励

https://www.freecodecamp.org/forum/t/freecodecamp-challenge-guide-sum-all-primes/16085