Challenge 19: First “nPrimes” prime numbers greater than “startAt”

Javascript




function generatePrimes(nPrimes, startAt) {
    let primes = [];
    let num = startAt + 1;
    while (primes.length < nPrimes) {
        if (isPrime(num)) {
            primes.push(num);
        }
        num++;
    }
    console.log(primes);
}
generatePrimes(5, 10);


Coding Challenge for Beginners | Coding Practice Challenges

Here’s a simple coding challenge suitable for beginners. This challenge involves writing a function in a programming language of your choice.

Table of Content

  • Challenge 1: Print Numbers from 1 to 10
  • Challenge 2: Print Odd Numbers Less Than 100
  • Challenge 3: Print Multiplication Table with 7
  • Challenge 4: Print All Multiplication Tables (1 to 10)
  • Challenge 5: Calculate Sum of Numbers from 1 to 10
  • Challenge 6: Calculate 10!
  • Challenge 7: Sum of Odd Numbers (10 to 30)
  • Challenge 8: Celsius to Fahrenheit Conversion
  • Challenge 9: Fahrenheit to Celsius Conversion
  • Challenge 10: Sum of Numbers in an Array
  • Challenge 11: Average of Numbers in an Array
  • Challenge 12: Positive Numbers in an Array (Solution 1)
  • Challenge 12: Positive Numbers in an Array (Solution 2)
  • Challenge 12: Positive Numbers in an Array (Solution 3)
  • Challenge 13: Maximum number in an array
  • Challenge 14: First 10 Fibonacci numbers without recursion
  • Challenge 15: nth Fibonacci number using recursion
  • Challenge 16: Check if a number is prime
  • Challenge 17: Sum of digits of a positive integer
  • Challenge 18: First 100 prime numbers
  • Challenge 19: First “nPrimes” prime numbers greater than “startAt”
  • Challenge 20: Rotate an array to the left 1 position
  • Challenge 21: Rotate an array to the right 1 position
  • Challenge 22: Reverse an array
  • Challenge 23: Reverse a string
  • Challenge 24: Merge two arrays
  • Challenge 25: Elements in the first or second array but not both
  • Challenge 26: Elements in the first array but not in the second
  • Challenge 27: Distinct elements in an array(Solution 1)
  • Challenge 27: Distinct elements in an array(Solution 2)
  • Challenge 28: Sum of first 100 prime numbers
  • Challenge 29: Distance between the first 100 prime numbers
  • Challenge 30: Add two positive numbers of indefinite size as strings(Solution 1)
  • Challenge 30: Add two positive numbers of indefinite size as strings(Solution 2)
  • Challenge 31: Number of words in a text(Solution 1)
  • Challenge 31: Number of words in a text(Solution 2)
  • Challenge 32: Capitalize the first letter of each word in a text
  • Challenge 33: Sum of numbers in a comma-delimited string
  • Challenge 34: Words inside a text
  • Challenge 35: Convert CSV text to a bi-dimensional array
  • Challenge 36: Convert a string to an array of characters
  • Challenge 37: Convert a string to an array of ASCII codes
  • Challenge 38: Convert an array of ASCII codes to a string
  • Challenge 39: Implement the Caesar cipher
  • Challenge 40: Bubble sort algorithm
  • Challenge 41: Distance between two points defined by their coordinates
  • Challenge 42: Check Circle Intersection
  • Challenge 43: Extract Column from 2D Array
  • Challenge 44: Convert Binary String to Number
  • Challenge 45: Sum of Numbers in Jagged Array
  • Challenge 46: Find Maximum Number in Jagged Array(Solution 1)
  • Challenge 46: Find Maximum Number in Jagged Array(Solution 2)
  • Challenge 47: Deep Copy Jagged Array
  • Challenge 48: Longest Word(s) in a String
  • Challenge 49: Shuffle Array of Strings
  • Challenge 50: Generate Unique Random Numbers
  • Challenge 51: Frequency of Characters in a String
  • Challenge 52: Calculate Fibonacci(500)
  • Challenge 53: Calculate 70! with High Precision

Similar Reads

Challenge 1: Print Numbers from 1 to 10

Javascript for (let i = 1; i <= 10; i++) {     console.log(i); }...

Challenge 2: Print Odd Numbers Less Than 100

...

Challenge 3: Print Multiplication Table with 7

Javascript for (let i = 1; i < 100; i += 2) {    console.log(i); }...

Challenge 4: Print All Multiplication Tables (1 to 10)

...

Challenge 5: Calculate Sum of Numbers from 1 to 10

Javascript for (let i = 1; i <= 10; i++) {   console.log(`7 * ${i} = ${7 * i}`); }...

Challenge 6: Calculate 10!

...

Challenge 7: Sum of Odd Numbers (10 to 30)

Javascript for (let i = 1; i <= 10; i++) {   for (let j = 1; j <= 10; j++) {     console.log(`${i} * ${j} = ${i * j}`);   } }...

Challenge 8: Celsius to Fahrenheit Conversion

...

Challenge 9: Fahrenheit to Celsius Conversion

Javascript let sum = 0; for (let i = 1; i <= 10; i++) {   sum += i; } console.log(sum);...

Challenge 10: Sum of Numbers in an Array

...

Challenge 11: Average of Numbers in an Array

Javascript function factorial(n) {   if (n === 0 || n === 1) return 1;   return n * factorial(n - 1); }    console.log(factorial(10));...

Challenge 12: Positive Numbers in an Array (Solution 1)

...

Challenge 12: Positive Numbers in an Array (Solution 2)

Javascript let sum = 0; for (let i = 11; i < 30; i += 2) {   sum += i; } console.log(sum);...

Challenge 12: Positive Numbers in an Array (Solution 3)

...

Challenge 13: Maximum number in an array

Javascript function celsiusToFahrenheit(celsius) {   return (celsius * 9/5) + 32; }    console.log(celsiusToFahrenheit(30));...

Challenge 14: First 10 Fibonacci numbers without recursion

...

Challenge 15: nth Fibonacci number using recursion

Javascript function fahrenheitToCelsius(fahrenheit) {   return (fahrenheit - 32) * 5/9; }    console.log(fahrenheitToCelsius(86));...

Challenge 16: Check if a number is prime

...

Challenge 17: Sum of digits of a positive integer

Javascript let numbers = [1, 2, 3, 4, 5]; let sum = numbers.reduce((acc, curr) => acc + curr, 0); console.log(sum);...

Challenge 18: First 100 prime numbers

...

Challenge 19: First “nPrimes” prime numbers greater than “startAt”

Javascript let numbers = [1, 2, 3, 4, 5]; let average = numbers.reduce((acc, curr) => acc + curr, 0) / numbers.length; console.log(average);...

Challenge 20: Rotate an array to the left 1 position

...

Challenge 21: Rotate an array to the right 1 position

Javascript function positiveNumbers(arr) {   return arr.filter(num => num > 0); }    console.log(positiveNumbers([-1, 2, -3, 4, -5]));...

Challenge 22: Reverse an array

...

Challenge 23: Reverse a string

Javascript function positiveNumbers(arr) {   let result = [];   for (let num of arr) {     if (num > 0) {       result.push(num);     }   }   return result; }    console.log(positiveNumbers([-1, 2, -3, 4, -5]));...

Challenge 24: Merge two arrays

...

Challenge 25: Elements in the first or second array but not both

Javascript function positiveNumbers(arr) {   let result = [];   arr.forEach(num => {     if (num > 0) {       result.push(num);     }   });   return result; }    console.log(positiveNumbers([-12, 22, -3, 41, -15]));...

Challenge 26: Elements in the first array but not in the second

...

Challenge 27: Distinct elements in an array(Solution 1)

Javascript let numbers = [5, 8, 3, 12, 7]; let max = Math.max(...numbers); console.log(max);...

Challenge 27: Distinct elements in an array(Solution 2)

...

Challenge 28: Sum of first 100 prime numbers

Javascript let fib = [0, 1]; for (let i = 2; i < 10; i++) {     fib[i] = fib[i - 1] + fib[i - 2]; } console.log(fib);...

Challenge 29: Distance between the first 100 prime numbers

...

Challenge 30: Add two positive numbers of indefinite size as strings(Solution 1)

Javascript function fibonacci(n) {     if (n <= 1) {         return n;     }     return fibonacci(n - 1) + fibonacci(n - 2); } console.log(fibonacci(5));...

Challenge 30: Add two positive numbers of indefinite size as strings(Solution 2)

...

Challenge 31: Number of words in a text(Solution 1)

Javascript function isPrime(num) {     if (num <= 1) return false;     for (let i = 2; i <= Math.sqrt(num); i++) {         if (num % i === 0) return false;     }     return true; } console.log(isPrime(11));...

Challenge 31: Number of words in a text(Solution 2)

...

Challenge 32: Capitalize the first letter of each word in a text

Javascript function sumOfDigits(num) {     let sum = 0;     while (num > 0) {         sum += num % 10;         num = Math.floor(num / 10);     }     console.log(sum); } sumOfDigits(123);...

Challenge 33: Sum of numbers in a comma-delimited string

...

Challenge 34: Words inside a text

Javascript function generatePrimes(count) {     let primes = [];     for (let i = 2; primes.length < count; i++) {         if (isPrime(i)) {             primes.push(i);         }     }     console.log(primes); } generatePrimes(100);...

Challenge 35: Convert CSV text to a bi-dimensional array

...

Challenge 36: Convert a string to an array of characters

Javascript function generatePrimes(nPrimes, startAt) {     let primes = [];     let num = startAt + 1;     while (primes.length < nPrimes) {         if (isPrime(num)) {             primes.push(num);         }         num++;     }     console.log(primes); } generatePrimes(5, 10);...

Challenge 37: Convert a string to an array of ASCII codes

...

Challenge 38: Convert an array of ASCII codes to a string

Javascript let arr = [1, 2, 3, 4, 5]; let temp = arr.shift(); arr.push(temp); console.log(arr);...

Challenge 39: Implement the Caesar cipher

...

Challenge 40: Bubble sort algorithm

Javascript let arr = [1, 2, 3, 4, 5]; let temp = arr.pop(); arr.unshift(temp); console.log(arr);...

Challenge 41: Distance between two points defined by their coordinates

...

Challenge 42: Check Circle Intersection

Javascript let arr = [1, 2, 3, 4, 5]; let reversed = arr.reverse(); console.log(reversed);...

Challenge 43: Extract Column from 2D Array

...

Challenge 44: Convert Binary String to Number

Javascript let str = "Hello, Geeks!"; let reversed = str.split('').reverse().join(''); console.log(reversed);...

Challenge 45: Sum of Numbers in Jagged Array

...

Challenge 46: Find Maximum Number in Jagged Array(Solution 1)

Javascript let arr1 = [1, 2, 3]; let arr2 = [4, 5, 6]; let merged = arr1.concat(arr2); console.log(merged);...

Challenge 46: Find Maximum Number in Jagged Array(Solution 2)

...

Challenge 47: Deep Copy Jagged Array

Javascript let arr1 = [1, 2, 3, 4]; let arr2 = [3, 4, 5, 6]; let result = arr1.filter(num => !arr2.includes(num)).concat(arr2.filter(num => !arr1.includes(num))); console.log(result);...

Challenge 48: Longest Word(s) in a String

...

Challenge 49: Shuffle Array of Strings

Javascript let arr1 = [1, 2, 3, 4]; let arr2 = [3, 4, 5, 6]; let result = arr1.filter(num => !arr2.includes(num)); console.log(result);...

Challenge 50: Generate Unique Random Numbers

...

Challenge 51: Frequency of Characters in a String

Javascript function getDistinctElements1(arr) {     return Array.from(new Set(arr)); }    let inputArray = [1, 2, 2, 3, 4, 4, 5]; let distinctArray1 = getDistinctElements1(inputArray); console.log(distinctArray1);...

Challenge 52: Calculate Fibonacci(500)

...

Challenge 53: Calculate 70! with High Precision

Javascript function getDistinctElements2(arr) {     return arr.filter((value, index, self) => self.indexOf(value) === index); }    let inputArray = [1, 2, 2, 3, 4, 4, 5]; let distinctArray2 = getDistinctElements2(inputArray); console.log(distinctArray2);...