HTMLify

Loop
Views: 235 | Author: djdj
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Loop</title>
    </head>
    <body>
        <center><h1>Check Prime Number</h1>
        <input type="textarea"><br><br>
        <button>Ans</button></center>
        <script>
            let btn = document.querySelector('button');
            let textarea = document.querySelector('input');
            textarea.addEventListener('click',input);
            function input(){
            let n = prompt("Enter a number: ");
            let c=0;

            for(let i=0;i<=n;i++){
                if(n%i==0){
                    c++;
                }
                if(c==2){
                    btn.textContent = n + ' is a prime number';
                }
                else if(c!=2){
                    btn.textContent = n + ' is not a prime number';
                }
            }
        }
        </script>
    </body>
</html>

Comments