How to Use Tan Method in TypeScript

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
  1. 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
  1. class tangent {  
  2.  constructor() {}  
  3.  tangentofnumber() {  
  4.   for (var n = 1; n <= 10; n++) {  
  5.    var span = document.createElement("span");  
  6.    var num = Math.tan(n);  
  7.    span.style.color = "green";  
  8.    span.innerText = "Tangent of nun " + n + "->" + num.toString() + "\n";  
  9.    document.body.appendChild(span);  
  10.   }  
  11.  }  
  12.  tangentofangel() {  
  13.   for (var n = 1; n <= 6; n++) {  
  14.    var x = 30;  
  15.    var z = 30 * n;  
  16.    var span = document.createElement("span1");  
  17.    var num = Math.tan(z);  
  18.    span.style.color = "blue";  
  19.    span.innerText = "Tangent of angels " + z + "->" + num.toString() + "\n";  
  20.    document.body.appendChild(span);  
  21.   }  
  22.  }  
  23. }  
  24. var s = new tangent();  
  25. s.tangentofnumber();  
  26. s.tangentofangel();  
tangentfunctiondemo.html
  1. <!DOCTYPEhtml>  
  2. <htmllang="en"  
  3.     xmlns="http://www.w3.org/1999/xhtml">  
  4.     <head>  
  5.         <metacharset="utf-8"/>  
  6.         <title>Tangent function</title>  
  7.         <linkrel="stylesheet"href="app.css"type="text/css"/>  
  8.         <scriptsrc="app.js">  
  9.         </script>  
  10.     </head>  
  11.     <body>  
  12.         <h1>tan() function in TypeScript HTML App</h1>  
  13.         <scriptsrc="app.js">  
  14.         </script>  
  15.         <divid="content"/>  
  16.     </body>  
  17. </html>  
app.js
  1. var tangent = (function() {  
  2.  function tangent() {}  
  3.  tangent.prototype.tangentofnumber = function() {  
  4.   for (var n = 1; n <= 10; n++) {  
  5.    var span = document.createElement("span");  
  6.    var num = Math.tan(n);  
  7.    span.style.color = "green";  
  8.    span.innerText = "Tangent of nun " + n + "->" + num.toString() + "\n";  
  9.    document.body.appendChild(span);  
  10.   }  
  11.  };  
  12.  tangent.prototype.tangentofangel = function() {  
  13.   for (var n = 1; n <= 6; n++) {  
  14.    var x = 30;  
  15.    var z = 30 * n;  
  16.    var span = document.createElement("span1");  
  17.    var num = Math.tan(z);  
  18.    span.style.color = "blue";  
  19.    span.innerText = "Tangent of angels " + z + "->" + num.toString() + "\n";  
  20.    document.body.appendChild(span);  
  21.   }  
  22.  };  
  23.  return tangent;  
  24. })();  
  25. var s = new tangent();  
  26. s.tangentofnumber();  
  27. s.tangentofangel();  
Output
 
final-result-type-script.gif
 
Referenced By
http://www.typescriptlang.org/


Similar Articles