
function nextPrime(n){
  if(n<2)return 2;
  if(n%2===0) n=n-1;
  for(let i =n;i=i+2;){
    if(isPrime(i)) return i;
  }
  
  function isPrime(num){
 
    if(num == 2){
        return true; 
    }else if(num % 2 == 0){
        return false;
    }
    var squareRoot = Math.sqrt(num);
    for(var i = 3; i <= squareRoot; i += 2) {
      if (num % i === 0) {
         return false;
      }
    }
    return true;
}
}