New Style of Writing Javascript

var Maths = {

    addNumbers: function(one, two) {
        return one + two;
    },

    subNumbers: function(one, two) {
        return one - two;
    },

    mulNumbers: function(one, two) {
        return one * two;
    },

    divNumbers: function(one, two) {
        if (two != 0)
            return one / two;
        else
            return "Division failed. Denominator cannot be Zero";
    }

}

function mathOperations() {
    alert(
        "Addition of 10 and 20 is " + Maths.addNumbers(10, 20) + "\n\n" +
        "Substraction of 10 and 20 is " + Maths.subNumbers(10, 20) + "\n\n" +
        "Multiplication of 10 and 20 is " + Maths.mulNumbers(10, 20) + "\n\n" +
        "Division of 10 and 20 is " + Maths.divNumbers(10, 20)
    );
}

Output:
New Style Javascript

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.