Skip to content

Addition of two numbers in JavaScript using if-else | Example code

  • by

Compute the sum of the two given integers (numbers) in JavaScript is very easy. Adding condition statement useful to use data or desire output on the condition based.

Addition of two numbers in JavaScript using if-else Example

HTML example code:- If the number is equal then do addition else find the difference using JavaScript.

<!DOCTYPE html>
<html>
<body>
    <script>
        function Addition(x, y) {
          if (x == y) {
            return (x + y);
        } 
        else
        {
            return (x - y);
        }
    }
    // Test cases
    console.log(Addition(10, 20));

    console.log(Addition(10, 10));
</script>

</body>
</html>

Output:

Addition of two numbers in JavaScript using if-else

Do comment if you have any question on this topic and code

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *