isPrime() Javascript represents a prime number checker function in Javascript.
Prime number is a number which is divisible by one and number itself.
like numbers 5,7,11,13,17, etc are prime numbers.
Prime number program in javascript using for loop
Below program uses for loop to check a number is prime or not.
Create a function isPrime() to check the number is prime or not.
- get the number
- check a number is divisible by 2 to num/2
- if divisible then not a prime number
- else it is a prime number.
Prime Number Checker
Prime Number Checker
Enter a number to check is it prime or not
In above program we have create isPrime() Javascript function.

Function is checking whether a number is prime or not.
To get text box value document.getElementById("num").value is used here document represents the html page and method getElementById is accepting a html elements id.
based on it is finding its value.
To show result in paragraph element with id result document.getElementById("result").innerHTML is used.