This website uses cookies to ensure you get the best experience on our website. Learn more

VS Educations

Thematic-Image

Divisibility Checker Source Code: How to design Divisibility Checker Using HTML CSS and JavaScript

A divisibility checker is a tool or algorithm used to determine if one number is divisible by another without leaving a remainder. It typically involves performing a division operation and checking if the remainder is zero. For example, to check if a number ( a ) is divisible by another number ( b ), you would divide ( a ) by ( b ) and see if the remainder is zero. If it is zero, then ( a ) is divisible by ( b ), otherwise it is not. Divisibility checkers are often used in mathematics and computer programming for various applications such as determining factors, simplifying fractions, and solving mathematical problems.

Divisibility Checker







Source Code

To design a basic divisibility checker using HTML, you can create a simple web page with input fields for the dividend and divisor, a button to perform the check, and an area to display the result. Here's a basic example:

<!DOCTYPE html>

<html>

<head>

    <title>Divisibility Checker</title>

    <style>

    label{

        padding:10px;

        font-size:22px;

        font-weight:800;

        margin:5px auto;

    }

    input[type=number]{

        font-size:18px;

        border:3px solid red;

        padding:5px;

        border-radius:10px;

    }

    </style>

</head>

<body>

<div style="text-align:center;padding:10px;border:3px solid blue; border-radius:14px;">

    <h1 style="font-size:28px;background:red;width:auto;color:#fff;padding:10px 0px;border-radius:12px;">Divisibility Checker</h1>

    <br>

    <label for="num">Enter a number/Dividend:</label>

    <input type="number" id="num">

    <br><br>

    

    <label for="divisor">Enter a divisor:</label>

    <input type="number" id="divisor">

    <br><br>

    

    <button style ="padding:10px; color:white; background:red;font-weight:800;font-size:20px;border-radius:8px;border:2px solid red; "onclick="checkDivisibility()">Check</button>

    

    <p style="font-size:25px;font-weight:800;" id="result"></p>


    <script>

        function checkDivisibility() {

            var num = document.getElementById("num").value;

            var divisor = document.getElementById("divisor").value;


            if (num % divisor === 0) {

                document.getElementById("result").innerHTML = num + " is divisible by " + divisor;

            } else {

                document.getElementById("result").innerHTML = num + " is not divisible by " + divisor;

            }

        }

    </script>

    </div>

</body>

</html>


This HTML code creates a basic web page with input fields for the dividend and divisor, a "Check" button, and a paragraph element to display the result. The JavaScript function checkDivisibility() is called when the button is clicked, which calculates whether the dividend is divisible by the divisor and displays the result accordingly.

Post a Comment

0 Comments