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

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s