9. Check a number is Prime or not

A prime number is a number that is divisible by 1 and itself only. First few prime numbers are: 2, 3, 5, 7, 11, 13, 17, …
A JavaScript uses the DOM model to check the input number is prime or not and display its corresponding alert message on the screen.

Examples:

Input : 4
Output : Not Prime

Input : 5
Output : Prime
  


        function checkPrimeNumber(number) {

        var n, i, flag = true;

        n = number;
        n = parseInt(n)
        for(i = 2; i <= n - 1; i++)
        if (n % i == 0) {
        flag = false;
        break;
        }

        // Check and display alert message
        if (flag == true)
        console.log(n + " is prime");
        else
        console.log(n + " is not prime");
        }


        checkPrimeNumber(4)
        checkPrimeNumber(5)

    

4 is not prime
5 is prime