Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

return the next higher prime number javascript

// Write a function that takes a number (a) as argument. If a is prime number, return a. If a is not prime number then return the next higher prime number.

const nextPrimeNumber = (num) => {
    for(let i = 2; i < num ; i++) {
        if(num % i === 0) {
            return nextPrimeNumber(num + 1)
        }

    }
    return num;
};

const input = 90;
console.log(nextPrimeNumber(input)); // 97
Source by upokary.com #
 
PREVIOUS NEXT
Tagged: #return #higher #prime #number #javascript
ADD COMMENT
Topic
Name
3+7 =