Tell us what’s happening:
Completing the first part of the challenge.
I’m aware that I need to be converting the sieve of Eratosthenes into code in order to solve this AND I thought I was doing this…
my failure proves otherwise.
Therefore, I’d like to know of what type my error is.
Am I making a mathematical error in exercising the sieve OR is it an incorrect application of the sieve into code?
Comments are below to indicate my reasoning.
Your code so far
function sumPrimes(num) {
//begin array with lowest prime
let array = [2,];
//iterate through array of numbers
for(let i = 2; i< num; i++){
//if number is odd and if number is not a multiple of the first four primes after 2, then push it into the array
if(i % 2 !== 0 && i !== i*(3,5,7 || 9)){
array.push(i)
}
}
console.log(array)
//sum primes within array together
return num;
}
sumPrimes(977);
//sieve of eratosthenes says primes can be found for any number greater than 2 by finding the odd numbers and the numbers that are not a multiple of any higher numbers
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-primes/