JavaScript program to check if a number is a prime number:

Created with Sketch.

JavaScript program to check if a number is a prime number:

let number = 11;
let isPrime = true;

if (number <= 1) {
  isPrime = false;
} else {
  for (let i = 2; i < number; i++) {
    if (number % i === 0) {
      isPrime = false;
      break;
    }
  }
}

if (isPrime) {
  console.log(number + " is a prime number");
} else {
  console.log(number + " is not a prime number");
}

Leave a Reply

Your email address will not be published. Required fields are marked *