-2

<script type = "text/javascript">
  function showPrimes(limit) {
    for (let number = 2; number <= limit; ++number) {
      let isPrime = true;
    }
  }
</script>

Above the code, I am currently working on so far. Not sure how to continue.

Prime
  • 2,809
  • 1
  • 7
  • 23
  • Put some effort to your code, at least put some pseudocode. Ok, your doing a for for each number from 2 to limit, then what? what you should do with each number? check if it's prime, right? (maybe you'll need another function that only check if it's prime or not) and if it's prime? store in a an array of result, maybe, if not, skip. Now try to put that algorithm as pseudocode and then translate it to javascript. Update you question with that. – pmiranda Oct 24 '20 at 02:19
  • You can probably use this answer [How to find prime numbers between 0 - 100?](https://stackoverflow.com/questions/11966520/how-to-find-prime-numbers-between-0-100) – Master12 Oct 24 '20 at 03:05

1 Answers1

1

function getPrimes(limit) {
    var sieve = [], i, j, primes = [];
    for (i = 2; i <= limit; ++i) {
        if (!sieve[i]) {
            primes.push(i);
            for (j = i << 1; j <= limit; j += i) {
                sieve[j] = true;
            }
        }
    }
    return primes;
}
console.log(getPrimes(100));
Prime
  • 2,809
  • 1
  • 7
  • 23