JavaScript Program to Demonstrate working of Arithmetic Operators

Write a JavaScript program to demonstrate working of arithmetic operators.



Source Code
<html>
<head>
    <title>Demonstrate use of Arithmetic operators</title>
</head>
<body>
    <script type = "text/javascript">
        var a = 33;
        var b = 10;
        var linebreak = "<br />";

        document.write("Here a = "+ a + " and b = " + b);
        document.write(linebreak);

        document.write("a + b = ");
        result = a + b;
        document.write(result);
        document.write(linebreak);

        document.write("a - b = ");
        result = a - b;
        document.write(result);
        document.write(linebreak);

        document.write("a / b = ");
        result = a / b;
        document.write(result);
        document.write(linebreak);

        document.write("a % b = ");
        result = a % b;
        document.write(result);
        document.write(linebreak);

        a = ++a;
        document.write("++a = ");
        result = ++a;
        document.write(result);
        document.write(linebreak);

        b = --b;
        document.write("--b = ");
        result = --b;
        document.write(result);
        document.write(linebreak);
    </script>
<p>Set the variables to different values and then try...</p>
</body>
</html>
Output





"Coding Hub - Learn to code" app now available on Google Play Store