Reader Level:
ARTICLE

How to Use Tan Method in TypeScript

Posted by Nitin Bhardwaj Articles | TypeScript October 15, 2012
In this article I will explain how to use tan() method in TypeScript with an example.
  • 1
  • 0
  • 1829

tan() Method in TypeScript

  • The tan() method of the math object is used to get the tangent of a number.

  • In the tan() method, the numeric value represents the tangent of the angle.

Syntax

Math.tan(number);

The following example shows how to use the tan() method and it returns the tangent of numbers in radians. We use the following steps to use this method.

Step 1

Open Visual Studio 2012 and click "File" -> "New" -> "Project...". A window is opened. Give the name of your application as "tangent" and then click ok.

Step 2

After this session the project has been created; your new project should look like this:

solotion-explorer-type-script.gif

Coding

tangent.ts

class tangent {

    constructor () {

 

    }

    tangentofnumber() {

        for (var n = 1; n <= 10; n++) {

            var span = document.createElement("span");

            var num = Math.tan(n);

            span.style.color = "green";

            span.innerText = "Tangent of nun " + n + "->" + num.toString() + "\n";

            document.body.appendChild(span);

 

        }

    }

    tangentofangel()

    {

        for (var n = 1; n <= 6; n++)

        {

            var x = 30;

            var z = 30 * n;

                var span = document.createElement("span1");        

                var num = Math.tan(z);

                span.style.color = "blue";

                span.innerText = "Tangent of angels " + z + "->" + num.toString() + "\n";

                document.body.appendChild(span);

         }

      }

}

var s = new tangent();

s.tangentofnumber();

s.tangentofangel();

 

tangentfunctiondemo.html

<!DOCTYPEhtml>

<htmllang="en"xmlns="http://www.w3.org/1999/xhtml">

<head>

    <metacharset="utf-8"/>

    <title>Tangent function</title>

    <linkrel="stylesheet"href="app.css"type="text/css"/>

    <scriptsrc="app.js"></script>

</head>

<body>

    <h1>tan() function in TypeScript HTML App</h1>    

    <scriptsrc="app.js"></script>

    <divid="content"/>

</body>

</html>

 

app.js

var tangent = (function () {

    function tangent() {

    }

    tangent.prototype.tangentofnumber = function () {

        for(var n = 1; n <= 10; n++) {

            var span = document.createElement("span");

            var num = Math.tan(n);

            span.style.color = "green";

            span.innerText = "Tangent of nun " + n + "->" + num.toString() + "\n";

            document.body.appendChild(span);

        }

    };

    tangent.prototype.tangentofangel = function () {

        for(var n = 1; n <= 6; n++) {

            var x = 30;

            var z = 30 * n;

            var span = document.createElement("span1");

            var num = Math.tan(z);

            span.style.color = "blue";

            span.innerText = "Tangent of angels " + z + "->" + num.toString() + "\n";

            document.body.appendChild(span);

        }

    };

    return tangent;

})();

var s = new tangent();

s.tangentofnumber();

s.tangentofangel();

 

Output

 

final-result-type-script.gif

Reference By

http://www.typescriptlang.org/

COMMENT USING

Trending up