Skip to main content

Membership is free!

Prime Number Checker

Enter a positive integer:

 

The Code:


    <div class="uk-container">
        <h1>Prime Number Checker</h1>
        <p>Enter a positive integer:</p>
        <input type="number" id="numberInput">
        <button onclick="checkPrime()">Check</button>
        <p id="result"></p>
    </div>

    <!-- Include UIKit JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.7.4/js/uikit.min.js"></script>
    <script>
        function checkPrime() {
            const number = parseInt(document.getElementById('numberInput').value);
            let isPrime = true;

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

            const resultElement = document.getElementById('result');
            if (isPrime) {
                resultElement.textContent = `The number ${number} is prime!`;
            } else {
                resultElement.textContent = `The number ${number} is not prime.`;
            }
        }
    </script>
Cron Job Starts