Prime numbers are natural numbers greater than 1 that have no positive divisors other than 1 and themselves. In other words, a prime number is a number that is only divisible by 1 and itself, without any remainder. For example, the first few prime numbers are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, ... Steps to get the solution: 1. If num is less that or equal to 1 , return false as by definition prime number is greater than 1 2. Loop over number, from i=2 to number 3. If number is 2(which is a prime number) , since i pointer is not less than 2, we will come out of loop and true will be returned. 4. If number is greater than 2, we will check if it is divisible by 2 5.If its not divisible (i.e remainer is not coming as 0) , then we will increment the i pointer and check again till we come out of loop. 6.If number is divisible by 2, its not a prime number and false will be returned. 7.If number is not divisible and we come out of the loop, we will return true as its not divisible by number other than 1 and itself Code:
``````
if(num<=1) {
return false;
}
for(let i=2;i < num;i++) {
if(num%i == 0) {
return false;
}
}
return true;
}
let num=11;