Write a function to check if a number is prime using node js

// Function to check if a number is prime
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;
}

// Example usage
const primeCheck = isPrime(17);
console.log(primeCheck);

 

Post your Answer