# Prime Numbers using JavaScript

What is Prime number?

A prime number can be divided only by itself or by 1 that number is called prime number.

For Example : The number 7 can be divided only by 7 or by 1 that means we say that the number 7 is a prime member.

Noted point:  The number 0 and 1 are not considered prime numbers.

The live demo example link https://jsfiddle.net/xfpe35tb/

JavaScript Program code

function isPrime(number) {

d = number - 1;

// If n is less than 2 or not an integer then we can say not a prime number.
if (number < 2) {
alert('If n is less than 2 or not an integer then we can say not a prime number.');
return false
}

if (number != Math.round(number)) {
alert('If n is less than 2 or not an integer then we can say not a prime number.');
return false
}

while (d > 1) {
if ((number % d) == 0) {
return false;
}
d--;
}
return true;
}

if (isPrime(1)) {
}
else { Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link.. My Tech Blog - https://www.code-sample.com/ My Books - Book 1 and Book 2
Prime Numbers using JavaScript Reviewed by Anil Singh on 5:30 AM Rating: (5)