CoffeeScript Math - tan()



Description

The tan() method accepts a number and returns its tangent value.

Syntax

Given below is the syntax of tan() method of JavaScript. We can use the same method in the CoffeeScript code.

Math.tan ( x )

Example

The following example demonstrates the usage of the tan() method in CoffeeScript. Save this code in a file with name math_tan.coffee.

value = Math.tan -30
console.log "The tangent value of -30 is : " + value 
         
value = Math.tan 90
console.log "The tangent value of 90 is : " + value 
         
value = Math.tan(2*Math.PI/180)
console.log "The tangent value of 2*Math.PI/180 is : " + value

Open the Node.js command prompt and compile the .coffee file as shown below.

c:\> coffee -c math_tan.coffee

On compiling, it gives you the following JavaScript.

// Generated by CoffeeScript 1.10.0
(function() {
  var value;

  value = Math.tan(-30);

  console.log("The tangent value of -30 is : " + value);

  value = Math.tan(90);

  console.log("The tangent value of 90 is : " + value);

  value = Math.tan(2 * Math.PI / 180);

  console.log("The tangent value of 2*Math.PI/180 is : " + value);

}).call(this);

Now, open the Node.js command prompt again, and run the CoffeeScript file as shown below.

c:\> coffee math_tan.coffee

On executing, the CoffeeScript file produces the following output.

The tangent value of -30 is : 6.405331196646276
The tangent value of 90 is : -1.995200412208242
The tangent value of 2*Math.PI/180 is : 0.03492076949174773
coffeescript_math.htm
Advertisements