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.
Reader Level:

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/

Login to add your contents and source code to this article
comments
COMMENT USING
PREMIUM SPONSORS
Infragistics is experts in technology and design, and passionate about helping you build highly performant and stylish applications that solve problems, deliver inspiration, and maximize results.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.