I have a problem with this. I have to find the first prime number greater than my const M. For example, I have M = 11, and I have to find the first prime number greater than M and it is 13. How Can I do that?
// isPrime
const M = 11
function isPrime(num) {
if (num < 2) return false;
for (let i = 2; i < num; i++) {
if (num % i == 0) return false;
}
return true;
}
console.log(isPrime(M))
And I would like find for M = 11, primeNumber = 13, for M = 15, primeNumber = 17 etc.